1

I have a .sh script that works fine if I run it in Terminal using "/Volumes/MEDIA/SERVER/SYNC.sh" But I can not get it to run the same in AppleScript Editor using: do shell script "/Volumes/MEDIA/SERVER/SYNC.sh" Also tried the above with bash in front, sh in front.

The shell script (SYNC.sh)

#!/bin/bash
login="uhh"
pass="uhh"
host="uhh.com"
remote_dir='~/private/sync'
local_dir="/Volumes/MEDIA/_/SYNCING"

base_name="$(basename "$0")"
lock_file="/tmp/$base_name.lock"
trap "rm -f $lock_file" SIGINT SIGTERM
if [ -e "$lock_file" ]
then
    echo "$base_name is running already."
    exit
else
    touch "$lock_file"
    lftp -p 22 -u "$login","$pass" sftp://"$host" << EOF
    set sftp:auto-confirm yes
    set mirror:use-pget-n 5
    mirror -c -P5 --Remove-source-files --log="/Volumes/MEDIA/SERVER/LOGS/$base_name.log" "$remote_dir" "$local_dir"
    quit
EOF
    # MOVE FINISHED FILES INTO DIRECTORY FOR CONVERSION
    mv /Volumes/MEDIA/_/SYNCING/movies/* /Volumes/MEDIA/SEEDBOX/MOVIES
    mv /Volumes/MEDIA/_/SYNCING/tvshows/* /Volumes/MEDIA/SEEDBOX/TVSHOWS
    mv /Volumes/MEDIA/_/SYNCING/books/* /Volumes/MEDIA/SEEDBOX/BOOKS
    mv /Volumes/MEDIA/_/SYNCING/music/* /Volumes/MEDIA/SEEDBOX/MOVIES

    # SHOW COMPLETED NOTIFICIATION 
    osascript -e 'display notification "Sync completed" with title "SEEDB0X"'

    rm -f "$lock_file"
    trap - SIGINT SIGTERM
    exit
fi

By not 'the same' what happens is only the

osascript -e 'display notification "Sync completed" with title "SEEDB0X"'

is run. With the script running through Terminal that only appears once syncing is done.

Thanks for any help!

4
  • Is that really your username, password and host all in plain text at the beginning of that script? :-) Commented Nov 8, 2016 at 1:08
  • How do you know that the 'mv' lines are not running? Or the 'rm' line, etc? Commented Nov 8, 2016 at 1:28
  • Well, that was super stupid of me. — I don't but neither is the sync by lftp. If I run that in Terminal it immediately picks up any new files. Commented Nov 8, 2016 at 1:31
  • OK, that makes more sense then ('mv' and 'rm' are likely to provide no output if run successfully). Try fully qualifying 'lftp' (as per my answer). Commented Nov 8, 2016 at 1:32

1 Answer 1

1

Did you install lftp yourself? I don't have a Mac handy to check if it's in Mac OS X by default or not. If you installed it, then it probably isn't in the PATH of the AppleScript environment and the bash script can't find it when run from there.

If this is the case, then you'll have to either:

  1. Fully qualify the path to 'lftp' (eg, "/usr/local/bin/lftp" or where ever it actually is) or
  2. Append to the PATH environment variable as used by AppleScript (or early in your bash script).

I think I'd go for option 1. Option 2 is overkill and more likely to adversely affect other things at other times.

PS. If you don't know where 'lftp' is installed, type 'which lftp' in the terminal.

Sign up to request clarification or add additional context in comments.

2 Comments

I did have to install LFTP by myself. Your thought makes sense. So I replaced lftp with the fullpath to it and that solved my problem, thanks!
I don't have the rep to up vote your comment, once I have enough rep I'll hit that up arrow for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.