I'm new to expecting and i want to create a script to ssh to a device,check is a process is running and display that the process is running or not.This is what i have so far
After executing this script i get an error.
#!/usr/bin/expect
set timeout -1
set ip "machine ip goes here"
set passwd "password goes here"
set pro "pgrep processtocheck | wc -l"
spawn ssh -p 222 machine@$ip
set test_id $spawn_id
expect -i $test_id "Password:"
send -i $test_id "$passwd\r"
expect "ipcs"
send -i $test_id "sudo su\r"
expect -i $test_id "#"
send -i $test_id "$pro\r"
expect -i $test_id "#"
if { $pro -ne 1 } {
echo "process stopped"
} else {
echo "process running"
}
exit