findutils-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Findutils-patches] xargs problem


From: aws backup
Subject: Re: [Findutils-patches] xargs problem
Date: Tue, 20 Dec 2016 23:35:56 +0200

Hi Berny,

thank you so much for the detailed instructions. 
It's almost working perfectly :-)
Needs just some tweaking I think.

Ok I started the screen command like this:

screen -dmS test /bin/bash -c "/path/to/fswatch.sh"

then the first script fswatch.sh:

#!/bin/bash
fswatch -0 -Ie '.*\.*$' -i '.*\.mp4$' /path/to/folder \
     | xargs -0 -n 1 /path/to/s3cmd.sh

then the second script s3cmd.sh:

#!/bin/bash
 filename="$(basename "$1")"
 terminal-notifier -message "s3cmd Upload '$filename' started"

 s3cmd put "$1" s3://bucket/ \
   | tee /path/to/logfile.txt \
   | tee >(mail -s 'Upload $filename' address@hidden) \
       && /usr/local/bin/terminal-notifier -message "s3cmd Upload of '$filename' done"

The second tee command is to get the output also in the screen terminal to see what's going on when I attach the screen.

Now what's happening. I change a filename. xargs transfers first the old file name (before renaming) to the script. Therefore I get the notifications upload started and upload done for the old filename and following error from s3cmd (also as email): 

ERROR: Parameter problem: Nothing to upload.
Null message body; hope that's ok

Which is correct because the old file is not existing anymore. 

Then xargs transfers the new file name (after renaming) to the script and everything works as expected. Just the variable "$filename" in the mail command doesn't work. The subject of the notification email is "Upload $filename".

How can I avoid that the old file name is transferred to the script?
Why does the mail command not understand $filename?

Thank you for your great help.
Wish you the best.
Robert


On 20 Dec 2016, at 16:01, Bernhard Voelker <address@hidden> wrote:

On 12/20/2016 01:30 PM, aws backup wrote:
Hi Berny,

thank you so much for your help.

First of all, I suggest to put everything you want to have in the
screen(1) session into a shell script.

I tried this first but I could not figure out how to transfer the xargs arguments to the script.
For example:

*fswatch -0 -Ie ".*\.*$" -i ".*\.mp4$" /path/to/folder | xargs -0 -n 1 -I {} /path/to/shellscript.sh*

shellscript.sh:

*s3cmd put {} s3://bucket/*

I get following failure message:

*ERROR: Parameter problem: Nothing to upload.*
*
So I get stuck already on the first point. 
Sorry I am a beginner in shell scripting.
How do I get it into the script?

If I understood your code well enough, then you just need to pass the
files found by fswatch to the following (untested) shellscript:

 -------<shellscript.sh>-------------
 #!/bin/bash
 filename="$(basename "$1")"
 terminal-notifier -message "s3cmd Upload '$filename' started"

 s3cmd put "$1" s3://bucket/ 2>&1 \
   | tee /path/to/logfile \
   |     >(mail -s "Upload '$filename'" address@hidden) \
       && terminal-notifier -message "s3cmd Upload of '$filename' done"
 -------</shellscript.sh>----------

I also removed the redundant invocation of the 2nd tee(1) in the above.

Then you could the following command into another schell script
which you could then pass on the "script -dmS ...."

 $ fswatch -0 -Ie '.*\.*$' -i '.*\.mp4$' /path/to/folder \
     | xargs -0 -n 1 /path/to/shellscript.sh

Of course, "set -x" and "xargs -t" are your friends here, too. ;-)

Have a nice day,
Berny


reply via email to

[Prev in Thread] Current Thread [Next in Thread]