通过expect实现scp密码自动输入

来源:互联网 发布:html怎么调用js方法 编辑:程序博客网 时间:2024/04/30 15:41

we first run expect  int shell cmd

if we don't install expect

we can use this to install expect in ubuntu:

sudo apt-get install expect



fiileName:scp.exp

# fileName:scp.exp#!/usr/bin/expect -f#Progame:#we copy today's wrf_data_*.dat from server#History:#2011/07/20 feng First release v1.0set timeout -1#we set password here set passwd password***#we use [exec date "+%Y%m%d"] to run shell cmd ,then the return value ,we put in DATEset DATE [exec date "+%Y%m%d"]#命令需要多个参数时set LASTDATE [exec date "-d last-day" "+%Y%m%d"]#where we put the file in localset LOCALPATH /home/feng/..........#给ssh运行进程加个壳,用来传递交互指令#scp today's wrf_data_*.datspawn scp **@ip:~/SZMB_forecast/wrf_data_${DATE}*.dat ${LOCALPATH}match_max 100000#when we need to put Password:expect -exact "Password:"#we send passwd to send -- "$passwd\r"expect eof#scp lastday's 23 's wrf_data_*.datspawn scp **@ip:~/SZMB_forecast/wrf_data_${LASTDATE}23.dat ${LOCALPATH}match_max 100000#when we need to put Password:expect -exact "Password:"#we send passwd to send -- "$passwd\r"expect eof#when we finish copying ,exitexit



we run this by type cmd in shell:

expect scp.exp

原创粉丝点击