lftp run jar file after mirror has changed files?

I want to sync an ftp directory with lftp, and run a jar file afterwards, but only if any files have been changed.

For testing, I just tried to execute another bash file after sync has finished, but it does not work:

lftp.sh:

lftp -f "
open $HOST
user $USER $PASS
lcd $SOURCEFOLDER
mirror --delete --verbose --on-change=test.sh $SOURCEFOLDER $TARGETFOLDER
bye
"

test.sh:

echo test ok

Result:

Unknown command `test.sh'.

Why, and how can I improve this? Absolute path also fails!

If not possible, how can I catch some kind of status code on exit to determine if there was a change on sync, and execute a command in case?

As well it would be fine if I could just get the number of new files transfered.

4

1 Answer

Manuals for lftp realy states that:

--on-change=CMD execute the command if anything has been changed

But idea is that CMD is lftp command, not Bash. So to execute local script 'task.sh' we should use lftp expression like source task.sh or ! task.sh.

SCRIPTFOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lftp -c "
open ${HOST}
user ${USER} ${PASS}
lcd $LOCALTARGETFOLDER
mirror --delete --verbose --on-change='source $SCRIPTFOLDER/test.sh' $REMOTESOURCEFOLDER $LOCALTARGETFOLDER
bye
"
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like