通过ssh分发文件。首先要在服务器端生成ssh密钥,把公钥内容发送到客户端/root/.ssh/authorized_keys文件中。
#chmod 700 authorized_keys //设置文件权限为700.其他用户不可写
1.最简单直接的分发脚本
#!/bin/bash ##向Ip尾数为5,6,7的地址分发文件 for n in 5 6 7 do ###--- $1表示第一个参数 scp $1 192.168.213.$n:/dir done
2.增加判断的分发脚本
#!/bin/bash ##向Ip尾数为5,6,7的地址分发文件 if [ $# -ne 1 ] then echo "please ensure $1 is 1" && exit fi for n in 5 6 7 do scp $1 192.168.213.$n:/dir 2>/dev/null x=`echo $?` if [ $x -eq 0 ] then echo "192.168.213.$n is right" else echo "192.168.213.$n is wrong" fi done
3.调用两个参数,即目录+文件
#!/bin/bash ##向Ip尾数为5,6,7的地址分发文件 if [ $# -ne 2 ] then echo "please ensure $1 is 1" && exit fi for n in 5 6 7 do scp $2/$1 192.168.213.$n:/ 2>/dev/null x=`echo $?` if [ $x -eq 0 ] then echo "192.168.213.$n is right" else echo "192.168.213.$n is wrong" fi done
本文由 Mr Gu 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Oct 12, 2016 at 02:46 pm