本文共 1229 字,大约阅读时间需要 4 分钟。
#!/bin/bash
if [ "$1" == "" ];
then
echo -e "\033[1mUsage:\033[0m autofile.sh configfilename url .\n \033[1m\033[5mNeed configfilename\033[0m\nconfigfilename is a f
ile which contain the ip list you want to patch.\n";
exit;
fi
if [ "$2" == "" ];
then
echo -e "\033[1mUsage:\033[0m autofile.sh configfilename url .\n \033[1m\033[5mNeed url\033[0m\nthe file is which you want to
distribute.\n";
exit;
fi
echo -e "\033[1m\033[5mWARNING: \033[0mHere is the address you want to distribute\033[1m`more $1`\033[0m
if you confirm to do this,please input the server password. otherwise,press ^c to abort the script."
#Get the password
read -p " password:" -s passwd
echo -e "\n"
for host in `more $1 | grep "^[1-9]" `
do
#Extract ip from autoconfig
ip=`echo $host | awk -F: '{print $1}'`
#Extract path from autoconfig
dir=`echo $host | awk -F: '{print $2}'`
#Display the information about host ip dir
echo -e "\033[1mhost=$host;ip=$ip;dir=$dir;\033[0m"
expect -c"
set timeout 600;
spawn /usr/bin/scp $2 $ip:/$dir
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$passwd\r\";}
}
expect eof"
done
[root@localhost ~]# cat autoconfig
192.168.16.192:/root
Usage:
[root@localhost ~]# ./autofile.sh autoconfig filename
转载地址:https://blog.csdn.net/weixin_33045961/article/details/116539840 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!