I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script):
#!/usr/bin/expect
set timeout 1
spawn ssh user@host
expect "*assword"
send "password\r"
expect "$"
#now I would do something like :
# if [ -z "\$(pidof some_process)"]
# or set found_pid $(pidof some_process)
I'm at loss how to set a variable using the things that pidof would output and make a conditional statement with it...
I've googled it for quite a some time but couldnt find an answer... Thanks in advance!
When you use keys for passwordless authentication, feeding a script into ssh becomes as easy as just feeding the script into it:
ssh user@host exec /bin/sh <<EOF
if [ -z "\$(pidof some_process)"]
then
...
fi
EOF
This is because ssh is designed to work this way. It's not designed to have passwords forcefed into it -- it's designed to prevent you from doing that -- which is why you needed to install the expect brute-forcing utility to do so.