1. 循环遍历所有节点
#!/bin/bash IpPrefix=192.168.1. User=root Pwd=000000 for((i=84;i<148;i++)) do { ./remote.exp $IpPrefix$i $User $Pwd >> tmp/$i echo "$i done!" }& done
2. 拷贝文件到所有节点
#!/usr/local/bin/expect -f set timeout -1 set IpAddr [lindex $argv 0] set User [lindex $argv 1] set Pwd [lindex $argv 2] spawn ssh $User@$IpAddr "cd /home/; rm -rf packages/; mkdir packages" expect { "yes/no" { send "yes "; expect "*assword:" { send "$Pwd " } } "*assword:*" { send "$Pwd "; } } expect eof spawn scp -r packages $User@$IpAddr:/home/ expect "*assword:*" { send "$Pwd "; } expect eof spawn ssh $User@$IpAddr "cd /home/packages;./install.sh;" expect "*assword:*" { send "$Pwd "; } expect "*mount finished*" { send 003 } expect eof
3. 所有节点上执行脚本
packages/install.sh
#!/bin/bash ./installExpect.sh disk=`sh getDisk.sh` disk="${disk////\/}" flag=`blkid | awk "/^${disk}/" | cut -d '"' -f 4` if [ "$flag" == "ext4" ]; then echo "Already mkfs..." else ./mkfs.exp fi tune2fs -c -1 -i 0 /dev/sdb mv /home/iscas/ /home/iscas2/ mkdir /home/iscas/ UUID=`tune2fs -l /dev/sdb | awk '/^Filesystem UUID:/{print $3}'` echo -e "UUID=$UUID /home/iscas ext4 defaults 1 2" >> /etc/fstab mount -a mv /home/iscas2/* /home/iscas/ rm -rf /home/iscas2/ echo "mount finished"
4. 获取节点最大磁盘名称
packages/getDisk.sh
#!/bin/bash disk=`fdisk -l 2>/tmp/null | awk 'BEGIN{Max=0} {if($0~/^Disk //){if($3>Max){disk=$2}}} END{print disk}' | cut -d : -f 1` echo $disk
5. 格式化最大磁盘
packages/mkfs.exp
#!/usr/bin/expect -f set timeout -1 set disk [exec sh getDisk.sh] spawn mkfs -t ext4 $disk expect "(y,n)" { send "y ";} expect eof
6. 挂载磁盘并设置属性
tune2fs -c -1 -i 0 /dev/sdb mkdir /home/iscas/ UUID=`tune2fs -l /dev/sdb | awk '/^Filesystem UUID:/{print $3}'` echo -e "UUID=$UUID /home/iscas ext4 defaults 1 2" >> /etc/fstab mount -a