| Advertise on warmetal.nl! Click for more information about advertising here. |
Did you find this website useful? Did I save you a lot of time? |
|
which expect
which should return with where the executable can be found on your system.
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $HOST -l root \"iso=`cat $configfile | grep isolation | wc -l`; if [ $iso != "0" ]; then echo "skip host $host"; else echo $append1 >> $configfile; echo "$append2" >> $configfile; fi;\";\
As you can see I used a variable for the configfile to check whether the configfile already has the required lines in it. I thought it would be nice check, especially because on the command line on the esx host this worked:
iso=`cat $configfile | grep isolation | wc -l`; if [ $iso != "0" ]; then echo "skip host"; else echo $append1 >> $configfile; echo "$append2" >> $configfile; fi
However, as explained this didn't work an I replaced to just show the number of lines it had with isolation so I could check manually for double lines if required.
#!/bin/sh # # Variable configfile="/etc/vmware/config" append1='isolation.tools.copy.disable = FALSE' append2='isolation.tools.paste.disable = FALSE' stty -echo; read -p "Input password:" A; stty echo; echo; for HOST in esxbox501 esxbox84 esxbox79 esxbox52 esxbox78\ esxbox51 esxbox53 esxbox54 esxbox76 esxbox77 esxbox71\ esxbox72 esxbox12 esxbox13 esxbox09 esxbox10 esxbox14\ esxbox15 esxbox16 esxbox17 esxbox18 esxbox20 esxbox19\ esxbox21 esxbox59 esxbox60 esxbox68 esxbox69 esxbox63\ esxbox64 esxbox85 esxbox62 esxbox61 do echo "Connecting to $HOST" expect -c "set timeout -1;\ spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $HOST -l root \"cat $configfile | grep isolation | wc -l; echo $append1 >> $configfile; echo $append2 >> $configfile;\";\ match_max 100000;\ expect *password:*;\ send -- $A\r;\ interact;" echo "Finished job on $HOST" done
Discussion