scp -r /etc/hosts root@ly151:/etc/ scp传输
ssh-keygen -t rsa -P "" 生成秘钥
ssh-copy-id -i .ssh/id_rsa.pub -p22 root@192.168.192.110 传秘钥
ssh -p 22 root@192.168.192.151
#!/bin/bash case $1 in "start") for host in ly151 ly154 ly110 do ssh $host "systemctl start mysqld" done ;; "stop") for host in ly151 ly154 ly110 do ssh $host "systemctl stop mysqld" done ;; "status") for host in ly151 ly154 ly110 do ssh $host "systemctl status mysqld" done ;; esac
cat xsync.sh #!/bin/bash #获取输入的参数,没有就退出 argCount=$# if [ $argCount == 0 ];then echo 'no args' exit 0 fi #获取文件名称 f=$1 fname=`basename $f` echo $fname #获取文件绝对路径 pdir=`cd -P $(dirname $f); pwd` echo $pdir #获取当前用户 user=`whoami` echo $user #循环拷贝 for host in ly151 ly154 do echo "*****$host*****" rsync -av $pdir/$fname $user@$host:$pdir done
cat autoinstall.sh
#!/bin/bash
jdk=true
installdir=/opt/soft
if [ ! -d "$installdir" ];then
mkdir $installdir
fiif [ "$jdk" = true ];then
echo "安装jdk"
tar -zxf /opt/install/jdk-8u111-linux-x64.tar.gz -C /opt/soft/
mv /opt/soft/jdk1.8.0_111 /opt/soft/jdk180
echo '#jdk' >> /etc/profile
echo 'export JAVA_HOME=/opt/soft/jdk180' >> /etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ' >> /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
fi