#!/usr/bin/expect -f
# ############################################################################## # # Filename: /usr/local/sbin/auto_tita_st_sh # # Purpose: Expect script designed to telnet into Nortel Ethernet Switches # and execute the CLI commands to confgure the appropriate timezone # information, including Day Light Saving time. # # # Author: BeiSen # # Date: June 1 2011 # # Version: 1.1 # # 源压缩包: /root/stnew/tita201107011505.tar (后缀名取决去压缩方式,时间取到分钟,避免一天多个版本发布而引起文件重名) # # 目标服务器: 10.22.1.48 # 10.22.1.49 # # 目录服务器文件路径:/var/www/htdocs/tita set DATE [exec date "+%Y%m%d%H%M%S"] set PATH [lindex $argv 0] set FILE [lindex $argv 1] set PATH2 [lindex $argv 2] # 开始循环 foreach IP { 10.22.1.48 10.22.1.49 10.22.1.7 10.22.1.8 } { spawn ssh set timeout 60 log_file -a /var/log/expect/expect$DATE.log expect "*(yes/no)*" send "yes\r" expect "*password:*" send "" expect "#" #####################################################################################################################################3 # #uploading (注意文件名和路径) # send "cd $PATH2\r" expect "#" send "mv $FILE $FILE.$DATE\r" expect "#" send "scp 10.22.1.54:$PATH\/$FILE $PATH2\r" expect "*(yes/no)*" send "yes\r" expect "*password:*" send "" expect "#" # # Backuping (备份方法可以自己定义) ################################################################################################## #send "mv $FILE $FILE.$DATE\r" # # #send "rm -rf tita\r" #expect "#" #send "tar -xzvf tita.tar.gz .\\" send "chown -R www:www $FILE\r" #--------------------------------------------------------------------------------------------------------------------------------------------------- expect "#" # purge cache (清空服务器的缓存) send "echo>/root/.ssh/known_hosts\r" expect "#" send "exit\r" expect eof }############################################################################---------完-----------########################################################
用法:假如要上传file.jpg到四台机器的/var/www/htdocs/11目录下,上传到一台管理机器上/var/stnew目录下,,然后执行 ./auto_Single_st.sh /var/stnew file /var/www/htdocs/11
执行前清空一下/root/.ssh/known_hosts内容