Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-23-2006, 11:37 AM   #1
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Rep: Reputation: 31
Question 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

Old 02-23-2006, 01:01 PM   #2
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,402
Blog Entries: 1

Rep: Reputation: 64
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 ?
Old 02-23-2006, 01:18 PM   #3
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Original Poster
Rep: Reputation: 31
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.
Old 02-24-2011, 04:59 PM   #4
Registered: Mar 2005
Location: Dayton, Ohio
Distribution: CentOS
Posts: 47

Rep: Reputation: 0
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
set timeout 180
set FAILED 2
expect {
timeout {
exit $FAILED
"password:" {
send "thepassword\r"
expect "sftp>"
send "cd /somedirectory\r"
expect {
"Couldn't change to directory"{
"sftp>" {
send "mget *.*\r"
expect {
"sftp>" {
send "rm *.*\r"
expect "sftp>"
send "quit\r"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect Script coolest Programming 7 02-16-2009 04:59 PM
cron job for expect script ruchitadesai Programming 9 05-27-2005 05:34 AM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 02:34 AM
BAD SU- from a cronned expect script ganninu Linux - General 1 07-18-2004 11:49 AM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 03:41 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration