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 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
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 '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

while IFS=: read -r f1 f2 f3
           ./ $f1 $f2 $f3;
done < server_details expect script
set host [lindex $argv 0];
set user [lindex $argv 1];
set password [lindex $argv 2];

set timeout 5
#set the correct prompt here
set prompt ":|#|\\\$"

eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host

expect "*assword:*"
send "$password\r"
expect "$prompt"

send "grep -i error /var/log/messages\r"

expect "$prompt"
send "exit\r"

expect eof
Server Information
# cat server_details

No comments:
Write comments