Shell Script Login Remote System Using SSH Update Server Status

By using shell script Login into the remote system using ssh and update there server status.I use the Important Linux command which one I used in the following shell script.

expect - maintain the interactive program.it will talk to other process via script. it is mainly used in the shell scripting to send the password & user name. These name come from send/expect.
expect >> wait for string from the process
send >> send the string to the process
while the interaction if expect get the string match with assword. it will send the password value.

expect \"*?assword:*\"
send -- \"$PASS\r\"

spawn >> start process
To write Bournce - Again Shell script To update the server details Using - expect -send -spwan command
#!/bin/bash
HOST="remote-hostname"
USER="remote-user"
PASS="remore-user-password"
CMD=$@
VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo “shell script Output”l
echo $VAR
Run the Shell Script
#sh execute.sh 'exim -bpc'
How To use spawn command
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
-bash: spawn: command not found
spawn command start with expect or you will get the error message

Correct Format
expect -c “spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD”
Wrong Format
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD”
-bash: spawn: command not found

Related post