Posts Tagged ‘expect’

nagios plugin using expect and shell scripting

Tuesday, October 13th, 2009

In some cases, if You need to monitor some remote host resource without SNMP or any other simplest way, maybe You need to write a shell nagios plugin calling an expect script. A quite strange way, I admit.

Well, You can write something like that:

MYRESULT=$(/usr/bin/expect – << EOF
set timeout -1

spawn ssh $MYUSERNAME@$MYHOSTNAME
expect {
ssword: {
send “$MYPASSWORD\r”
}
}
expect {
bash-prompt {
send “$MYCOMMAND\r”
}
}
expect {
bash-prompt {
send “exit\r”
}
}
EOF)