shell拷贝文件到另一台机器

#!/bin/bash

data=$(date "+%Y-%m-%d %H:%M:%S")
ip='192.168.10.14'
password='fan'
gitBak='/var/opt/gitlab/backups/'
delFile=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | head -1`
count=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | wc -l`

if [ $count -gt 4 ];then
  rm $delFile
  echo "$data -- delete $delFile" >> $gitBak/log.txt
fi
gitlab-rake gitlab:backup:create RAILS_ENV=production CRON=1
if [ $? -ne 0 ];then
  echo "$data -- 脚本执行失败" > $gitBak/log.txt
fi
copyFile=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | tail -1`
/usr/bin/expect <<EOF
spawn scp -rp $copyFile root@$ip:/opt
expect {
"(yes/no)?" { send "yes\n"; expect "*assword:" { send "$password\n"}}
"*assword:" { send "$password\n" } 
}
expect eof
EOF
posted @ 2019-05-20 22:38  博客萨斯州  阅读(1249)  评论(0编辑  收藏  举报