批量传输脚本并执行-scp

$1 file内容:
10.1.1.2,22,root,123456,/tmp

脚本内容:

#!/bin/bash
#========2018-08-28=======>>
#. /etc/init.d/functions
if [ $# -ne 1 ] ;then
#        action  "need mail server file!" /bin/false
	echo "need mail server file!"
        exit 1
fi
date=$(/bin/date "+[%F--%T]")
		while read line
		do
		arr=(${line//,/ })
		ip=${arr[0]}
		port=${arr[1]}
		user=${arr[2]}
		pass=${arr[3]}
		path=${arr[4]}
#================scp=======one====>>
			expect -c "
			spawn /usr/bin/scp -pP$port /tmp/1.sh $user@$ip:$path
			expect	{
				\"*(yes/no)?\" 
					{
						exp_send \"yes\r\";exp_continue
						expect \"*password:\" { send \"${pass}\r\" }
					}				
				\"*password:\"
					{
						send \"${pass}\r\"
					}
				}
			expect eof 
			send_user \"eof1\n\" 
			"
#================sh=======one========>>
			expect -c "
			set timeout 1
			spawn /usr/bin/ssh -p$port $user@$ip
			expect	{
				\"*(yes/no)?\" 
					{
						exp_send \"yes\r\";exp_continue
						expect \"*password:\";exp_continue
								{ 
									exp_send \"${pass}\r\"
									expect \"#\" { send \"/tmp/1.sh \r\" }	
								 }
					}				
				\"*password:\"
					{
						send \"${pass}\r\";exp_continue
						expect \"#\" { send \"/tmp/cpFile.sh \r\" }
					}
				}
			expect eof 
			send_user \"eof2\n\" 
			"
#========================end=========>>
		done <$1

你可能感兴趣的:(shell)