AI智能
改变未来

shell脚本 实现批量分发文件

!/bin/bashIP=(192.168.189.162192.168.189.163)while truedoclear#菜单echo -e \"\\033[1;34m欢迎使用该程序:2.批量分发文件q.退出\\033[0m\"#获取用户的选择read -ep \"请选择:\"  menu#判断用户的选项case $menu in1)while truedoread  -ep \"请输入您要下发的命令(返回主页:q):\"  cmdif [ $cmd == \"q\" -o $cmd == \"Q\" ];thenbreakficlearfor i in ${IP[@]}doecho \"------------------$i--------------------\"ssh  root@$i \"$cmd\"if [ $? -eq 0 ];thenecho -e \"\\033[1;32m $i主机执行成功!\\033[0m\"elseecho -e \"\\033[1;31m $i主机执行失败!\\033[0m\"fidonedone;;2)while truedoread -ep \"请输入源文件路径,多个文件空格分开(返回主页:q):\" fileif [ $file == \"q\" -o $file == \"Q\" ];thenbreakfifor i in ${IP[@]}doscp $file root@$i:/root/if [ $? -eq 0 ];thenecho -e \"\\033[1;32m $i文件拷贝成功!\\033[0m\"elseecho -e \"\\033[1;31m $i文件拷贝失败!\\033[0m\"fidonedone;;q|Q)echo \"退出程序!\"exit;;*)echo \"输入有误!退出程序!\"exitesacdone
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » shell脚本 实现批量分发文件