linux expect 判断项实现sftp目录创建和上传的功能

#!/usr/bin/expect
# 脚本名称: sftp.sh
# 执行例程 expect sftp.sh '192.168.1.1' 'user' 'passwd' '/DXP/DATA/EDW/ROUT/BEIJING_2016-12-01.DAT' '/app/sftp/BCSS_FILE/BCSS/EC/201907'


if {$argc < 5} {

puts "Usage:cmd <host> <username> <password> <src_file> <dest_file>"

exit 1

}



set timeout 600

set host [lindex $argv 0]

set username [lindex $argv 1]

set password [lindex $argv 2]

set src_file [lindex $argv 3]

set dest_file [lindex $argv 4]



spawn sftp $username@$host



expect {

"yes/no" {send "yes\n"; exp_continue;}

"*password:" {send "$password\n"}

}



expect "sftp>" {send "cd $dest_file\n"}



expect {

"No such file or directory" {send "mkdir $dest_file\n";exp_continue;}

"sftp>" { send "put $src_file $dest_file\n"}

}



expect {

"No such file or directory" { send_user "No such file\n";send "quit\r";exit 2 }

"100%" { send_user "finish\n";send "quit\r";exit 0}

}

expect eof




支持原创

博客:   https://blog.csdn.net/clark_xu

代码:https://github.com/clark99

微信公众号:clark_blog

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值