linux - FTP copy file to remote machine failed in Bash Script -


i have made bash script backup files , send remote machine file gets created ftp failed put directory mentioned problem lies when ftp tries copy file. here script :

#!/bin/bash  #backup root directories destination="/backup"; host=localhost user=qwerty pass=qwerty count=$(cd /backup/ && ls -l | wc -l); echo $count; dir="/dev /sys /etc /www /var /rom /root /dev /overlay /bin /sbin /nebero /lib /usr"; dir="/root/pen"; dir_1="/dev /sys /etc /www /var /rom /root /dev /overlay /bin /sbin /nebero /lib /usr /mnt"; dir_1="/root/pen";      if [ "$1" = "full_backup" ]              tar cvf $destination/full_backup_`date +%d-%m-%y_%h:%m`.tar `echo $dir_1` >>/dev/null;          if [ $count -eq 1 ]                 new=$(ls -t /*back*/ | head -n2);         else         new=$(ls -t /*back*/ | head -n2 | sed '2!d');         fi        elif [ "$1"  = "conf_backup" ]             tar cvf $destination/conf_backup_`date +%d-%m-%y_%h:%m`.tar `echo $dir` >>/dev/null;         new=$(ls -t /*back*/ | head -n2 | sed '1!d');      else         echo "please provide argument";         exit      fi  file=$new  ftp -in $host <<eof user $user $pass pwd cd /rav put $file bye eof 

first of all, looks purpose of ls commands find file have created. can skip if save filename variable prior calling tar:

filename=full_backup_`date +%d-%m-%y_%h:%m`.tar 

then use $destination/$filename in tar commands , $filename in ftp command.

regarding failed upload, sure in correct directory locally?

these ftp commands changing directories:

  • cd: changes directory on remote machine
  • lcd: changes working directory on local machine

make sure both correct before executing put.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -