标签:shell 脚本
下月有一个系统上线23台主机,虚拟机模板不带应用用户,所以只能手动来一个一个建立,于是想到了写一个小脚本解脱重复劳动的痛苦。
整个脚本分为脚本和配置文件:
配置文件如下:
username=root password=1q2w3e ip1=192.168.10.129 ip2=192.168.10.130 ip3=192.168.10.128
脚本文件如下:
UNAME=`cat ./sysinfo.conf| grep username|awk -F ‘=‘ ‘{print $2}‘` PASSWD=`cat ./sysinfo.conf| grep password|awk -F ‘=‘ ‘{print $2}‘` cat ./sysinfo.conf|grep ip|awk -F ‘=‘ ‘{print $2}‘ | while read IP do ping -c 2 $IP >/dev/null 2>&1 conn_check=$? if [ $conn_check -eq 0 ]; then expect << EOF spawn ssh $UNAME@$IP expect "*password:" { send "$PASSWD\r" } expect "*]#" { send "lvcreate -L 500M -n lv_test system\r" } expect "*]#" { send "mkdir /test\r" } expect "*]#" { send "mkfs.ext4 /dev/system/lv_test\r" } expect "*]#" { send "mount /dev/system/lv_test /test\r" } expect "*]#" { send "exit\r" } EOF elif [ -s ./error.log ]; then echo "`date` The hostmachine $IP is not connected!">>./error.log else echo "`date` The hostmachine $IP is not connected!">./error.log fi done
备注:里面的IP为案例IP并非我主机实际IP
本文出自 “老白的博客” 博客,请务必保留此出处http://laobaiv1.blog.51cto.com/2893832/1978665
标签:shell 脚本
原文地址:http://laobaiv1.blog.51cto.com/2893832/1978665