LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 02-23-2006, 10:37 AM   #1
d3funct
Member
 
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

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

Rep: Reputation: 68
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, 12:18 PM   #3
d3funct
Member
 
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, 03:59 PM   #4
Cerephim
Member
 
Registered: Mar 2005
Location: Dayton, Ohio
Distribution: CentOS
Posts: 49

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 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"
 
  


Reply


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 03:59 PM
cron job for expect script ruchitadesai Programming 9 05-27-2005 04:34 AM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 01:34 AM
BAD SU- from a cronned expect script ganninu Linux - General 1 07-18-2004 10:49 AM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

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