LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Can I use 'if' statements in Expect script? (http://www.linuxquestions.org/questions/programming-9/can-i-use-if-statements-in-expect-script-418765/)

d3funct 02-23-2006 10:37 AM

Can I use 'if' statements in Expect script?
 
I'm upgrading the firmware on some (200) IBM 7043-150 and 7043-170 workstations. I have two directories /ui/admin/fwupdate/170/170* and /ui/admin/fwupdate/150/150* which are NFS automounted. I am attempting to write an Expect script that will log in, su - to root run 'uname -M |cut -d"-" -f2' to get the w/s type (150 or 170), run 'lsmcode' to determine the firmware level and then echo "echo 1 | /ui/admin/fwupdate/150 or 170/150* or 170*" > /tmp/at_fwupdate, then run chmod u+x /tmp/at_fwupdate, then run at -f /tmp/fwupdate 0300 tomorrow and exit the w/s, continuing on to the next in my list created by variable set hostlist "list of hostnames here".

But...afer I 'expect "150"' or 'expect "170"'from the uname -M above, how do I take that output and make it a variable that I can do something with. Like if the workstation is a 150 model then run the 'lsmcode' and if the firmware is not 04195 then echo "echo 1 | {path to firmware upgrade" > /tmp/at_fwupdate, chmod u+x /tmp/at_fwupdate and create the atjob. Likewise for the 170 but if the firmware is not 05195 then do the echo.
Hope this makes sense, and hope you can help.

Thanks a bunch

Jon

marozsas 02-23-2006 12:01 PM

Wow, too hard to understand !
Try to reformulate your question leaving the specific commands aside. For example, we don't know what "echo 1 | /ui/admin/fwupdate/150" is supposed to do.
Can you cut down your problem until you get a couple of simple and objective bash questions ?

d3funct 02-23-2006 12:18 PM

I'm using ksh, not bash on AIX 4.3.3. But this is an /usr/local/bin/expect script. Anyway I want my expect script to login as root to a host and check the machine type either IBM 7043-150 or 7043-170. Then I want it to run 'lsmcode' which checks the firmware level and the command returns not equal to either 04195 or 05195 I want it to echo "echo 1 | /ui/admin/fwupdate/150/150*" to a file called /tmp/at_fwupdate (if it's a 7043-150, change the 150 in the path to 170 for a 7043-170). Then I want to make the file executable "chmod u+x /tmp/at_fwupdate", and create an 'at' job to run at 0300 the next morning "at -f /tmp/at_fwupdate 0300 tomorrow".

My question is can I put 'if' statements in my expect script using the replies from 'uname -M' which determines machine type, and 'lsmcode' which determines the firmware level. This is not an AIX specific question, but rather an Expect scripting question.

Cerephim 02-24-2011 03:59 PM

Wow, this is a really old post, but in the hope that someone may find this info useful, I'm posting it...

You can nest 'expects', like this:

#/usr/bin/expect -f
spawn sftp root@xxx.xxx.xxx.xxx
set timeout 180
set FAILED 2
set CDFAILED 3
expect {
timeout {
exit $FAILED
}
"password:" {
send "thepassword\r"
}
}
expect "sftp>"
send "cd /somedirectory\r"
expect {
"Couldn't change to directory"{
exit $CDFAILED
}
"sftp>" {
send "mget *.*\r"
expect {
"sftp>" {
send "rm *.*\r"
}
}
}
}
expect "sftp>"
send "quit\r"


All times are GMT -5. The time now is 11:05 AM.