I have a hosts containing file say /tmp/hostlist
which requires username & password to login and I am using expect command to login hosts and execute command and come out like below in my bash script.
#!/bin/bashexport file="/tmp/hostlist"export cmd="hostname -f"script=$(cat <<'END_OF_SCRIPT' set timeout 120 set f $::env(file) set fh [open $f r] while {[gets $fh server_name] != -1} { spawn sudo -i -u rcuser ssh $server_name send "\r" expect "$server_name login:" send "root\r" expect "Password:" send "passwd\r" send "$::env(cmd)\r" send "exit\r" expect eof } close $fhEND_OF_SCRIPT)VAR=$(expect -c "$script")echo "$VAR" >/tmp/outexp-----------------
My requirement is to execute parallely on all the hosts..Can this be done fork ? Please help me in modifying above code to make it parallel connection.