标签:
#!/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
#!/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\n"; expect "*assword:" { send "$Pwd\n" } } "*assword:*" { send "$Pwd\n"; } } expect eof spawn scp -r packages $User@$IpAddr:/home/ expect "*assword:*" { send "$Pwd\n"; } expect eof spawn ssh $User@$IpAddr "cd /home/packages;./install.sh;" expect "*assword:*" { send "$Pwd\n"; } expect "*mount finished*" { send \003 } expect eof
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\t/home/iscas\text4\tdefaults\t1\t2" >> /etc/fstab mount -a mv /home/iscas2/* /home/iscas/ rm -rf /home/iscas2/ echo "mount finished"
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
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\r";} expect eof
tune2fs -c -1 -i 0 /dev/sdb mkdir /home/iscas/ UUID=`tune2fs -l /dev/sdb | awk ‘/^Filesystem UUID:/{print $3}‘` echo -e "UUID=$UUID\t/home/iscas\text4\tdefaults\t1\t2" >> /etc/fstab mount -a
标签:
原文地址:http://www.cnblogs.com/dorothychai/p/4487380.html