Mailinglist Archive: opensuse (1264 mails)

< Previous Next >
Re: [opensuse] Quick question: how to call a script function from "find"? - using parallel
On 2017-06-14 08:12, Vojtěch Zeisek wrote:
Dne úterý 13. června 2017 23:38:24 CEST, Carlos E. R. napsal(a):
On 2017-06-13 13:59, Vojtěch Zeisek wrote:
Dne úterý 13. června 2017 9:19:25 CEST, Per Jessen napsal(a):
Carlos E. R. wrote:
I usually tend towards 'xargs' because it can be parallelised, but in
this case, I would probably do this:

find /home/cer/Fusion/Videos/ -type d |\
while read d;
do

sudo chown cer:cer $d
chmod u+r+w+x,g+w+x,o+r-w-x,+t $d
sudo chown cer-g:cer $d
and-whatever-else-you-want.

done

find /home/cer/Fusion/Videos/ -type d | parallel "sudo... && chmod...
&&..." This is my favorite style. :-)

I have to investigate that parallel command, but in this case I need the
commands to be sequential.

Sequential? Why do You need to process the files one-by-one? Construction
parallel "sudo chown cer:cer '{}' && chmod u+r+w+x,g+w+x,o+r-w-x,+t '{}' &&
sudo chown cer-g:cer '{}' && ..."
is of course sequential (because of '&&'). Or am I missing some point?


cer@Isengard:~/Fusion> time ./_Cambiar_permisos_Videos

real 0m10.549s
user 0m8.363s
sys 0m1.506s
cer@Isengard:~/Fusion> time ./_Cambiar_permisos_Videos

real 0m10.699s
user 0m8.352s
sys 0m1.527s
cer@Isengard:~/Fusion>

Now try parallel:

cer@Isengard:~/Fusion> time ./_Cambiar_permisos_Videos
Academic tradition requires you to cite works you base your article on.
When using programs that use GNU Parallel to process data for publication
please cite:

O. Tange (2011): GNU Parallel - The Command-Line Power Tool,
;login: The USENIX Magazine, February 2011:42-47.

This helps funding further development; and it won't cost you a cent.
If you pay 10000 EUR you should feel free to use GNU Parallel without citing.

To silence the citation notice: run 'parallel --bibtex'.

chmod: changing permissions of '/home/cer/Fusion/Videos/': Operation not
permitted
chmod: cannot access '/home/cer/Fusion/Videos/Major\ Crimes': No such file or
directory
chmod: cannot access '/home/cer/Fusion/Videos/Buffy,\ cazavampiros': No such
file or directory
chmod: cannot access '/home/cer/Fusion/Videos/Buffy,\ cazavampiros/Temporada\
7': No such file or directory


Oops.

The directory:

/home/cer/Fusion/Videos/Major\ Crimes/

does exist, despite the error above.



script is:

#!/bin/bash

#find /home/cer/Fusion/Videos/ -type d \
# -exec sudo chown cer:cer '{}' \; \
# -exec chmod u+r+w+x,g+w+x,o+r-w-x,+t '{}' \; \
# -exec sudo chown cer-g:cer '{}' \; \
# -exec sudo setfacl -m u:wwwrun:rx '{}' \;

find /home/cer/Fusion/Videos/ -type d | parallel parallel "sudo chown cer:cer
'{}' && chmod u+r+w+x,g+w+x,o+r-w-x,+t '{}' && sudo chown cer-g:cer '{}' &&
sudo setfacl -m u:wwwrun:rx '{}'"


So I can not replace directly with parallel.

Problem one: sudo chown has not run because chmod fails. Maybe commands are not
run in sequence after all.

Problem two: directories are not found.


--
Cheers / Saludos,

Carlos E. R.
(from 42.2 x86_64 "Malachite" at Telcontar)

< Previous Next >