Reputation: 33
I'm trying to echo $file_name once the transfer is complete. However I cannot find any reference for how to create the variable in LFTP that displays the file name of what was just downloaded.
The code:
#!/bin/bash
login="myusername"
pass="notmypassword"
host="my.hosting.server"
remote_dir='/Path/To/Remote/Dir/.'
local_dir="/Path/To/Local/Dir/"
file_name=**the name of the file im downloading**
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 -u $login,$pass $host << EOF
set ftp:ssl-allow no
set mirror:use-pget-n 5
mirror -c -x "\.r(a|[0-9])(r|[0-9])$" -P5 --log="/var/log/$base_name.log" "$remote_dir" "$local_dir"
echo $file_name
quit
EOF
#osascript -e 'display notification "$file_name Downloaded" with title "Media Server"'
rm -f "$lock_file"
trap - SIGINT SIGTERM
exit
fi
I figured that it would be rather simple to echo the current file and then also add this variable into my osascript to trigger a notification on OSX that a file has been successfully transferred, but for the life of me I can't figure out how.
What am I doing wrong???
Cheers!
Upvotes: 2
Views: 3740
Reputation: 1481
Use a file verification script:
set xfer:verify on
set xfer:verify-command /home/user/bin/file-transferred
The script output (FD 1,2) is redirected, but you can use /dev/tty
to output the file name to the terminal:
#!/bin/sh
echo "$1" >/dev/tty
Alternatively, open another descriptor:
lftp 3>&1 <<EOF
...
EOF
and redirect output there:
#!/bin/sh
echo "$1" >&3
Upvotes: 2
Reputation: 920
This script will echo each file that was transferred, feel free to clean it up and modify it to suit your needs:
#!/bin/bash
echo "Script started."
download_directory="${HOME}/downloads/"
echo "Downloading to ${download_directory}"
rm ${download_directory}/*
download_log=$(mktemp)
lftp <<- EOF > ${download_log}
# elided connection details, enter your own
open
mirror -v . ${download_directory}
quit
EOF
cat ${download_log} | awk ' { print $3 } ' | sed 's/`//' | sed 's/'\''//' | xargs echo "Downloaded:"
rm -f ${download_log}
echo "Script successfully ended."
Example output:
=> ./foobar.sh
Script started.
Downloading to /home/downloads/
Downloaded: something1.yes testfile.txt
Script successfully ended.
Upvotes: 2