Bash script - Starting lftp inside gnu screen ============================================= Public domain ******************************************************************************** ### Starting gnu screen with multiple lftp instances and leave screen open after command compeletion Mirror a local directory to multiple remote websites. #!/bin/bash # Creat new session screen -dmS upload sleep 1 # site1.com cat > ~/screen-cmd-file << EOF screen select 1 title "site1.com" exec bash -c "echo 'set ftp:ssl-allow false;mirror --reverse --delete --only-newer --verbose /mnt/usb/Website-Backup/homepage/ /public_html/' | lftp -u user1,pass1 site1.com" EOF screen -r upload -X source ~/screen-cmd-file rm ~/screen-cmd-file # site2.com cat > ~/screen-cmd-file << EOF screen select 2 title "site2.com" exec bash -c "echo 'set ftp:ssl-allow false;mirror --reverse --delete --only-newer --verbose /mnt/usb/Website-Backup/homepage/ /public_html/' | lftp -u user2,pass2 site2.com" EOF screen -r upload -X source ~/screen-cmd-file rm ~/screen-cmd-file ******************************************************************************** ### Starting gnu screen with single lftp instance and close screen after command compeletion Making backup from a local directory to a remote ftp server #!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin BAK=/tmp/backup.sh # Creat backup script cat > $BAK << EOF PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin; D=\$(date "+%F %T"); echo "\$D -- Backup Startd." >> /root/backup.log; echo 'set mirror:parallel-directories true; set mirror:parallel-transfer-count 10; mirror --reverse --delete --only-newer --verbose /storage/database/ /database/' | lftp 172.16.20.2; D=\$(date "+%F %T"); (echo "\$D -- Backup finished.";echo "-----") >> /root/backup.log rm $BAK EOF chmod +x $BAK # Start backup screen -dmS "backup" sleep 1 screen -S "backup" -X screen $BAK # kill useless screen window SCR_PID=$(echo $(screen -ls | grep backup | awk -F '.' '{print$1}')) [ "$SCR_PID" == "" ] && exit BASH_PID=$(pstree -p | grep $SCR_PID | sed -e 's,.*bash(,,' -e 's,),,') [ "$BASH_PID" == "" ] && exit kill -KILL $BASH_PID ******************************************************************************** _BY: Pejman Moghadam_ _TAG: lftp, screen, bash-script, bash_ _DATE: 2012-08-18 14:55:49_