HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Expect If Statement
Operating System - HP-UX
1834800
Members
2609
Online
110070
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2006 07:32 PM
07-03-2006 07:32 PM
Expect If Statement
Hello,
I can't for the life of me remember where, but I've seen a script in the past that used expect, but also had an if statement within the expect code. Can anyone tell me the syntax of if statements in expect?
I want to kind of do something like this...
Send a command, and get expect to do one thing if it gets one string back but do something else if it gets another string back. So for example, if I ran a command, but the response was "No such file or directory" I want the script to do a certain action, but if the command succeeds and expect gets back something else I want the script to do a different action...does that make sense?
Regards - Lee
I can't for the life of me remember where, but I've seen a script in the past that used expect, but also had an if statement within the expect code. Can anyone tell me the syntax of if statements in expect?
I want to kind of do something like this...
Send a command, and get expect to do one thing if it gets one string back but do something else if it gets another string back. So for example, if I ran a command, but the response was "No such file or directory" I want the script to do a certain action, but if the command succeeds and expect gets back something else I want the script to do a different action...does that make sense?
Regards - Lee
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2006 07:50 PM
07-03-2006 07:50 PM
Re: Expect If Statement
check whether this will help
#executes the command
send "$cmd\r"
#looks for pattern for the result
expect -re "\[#%$].*" {
#$expect_out(buffer) expect variable that stores the output of the command. split this by \r\n to get the result
set dataBuff [split $expect_out(buffer) "\r\n"]
set result [lindex $dataBuff 2]
}
#syntax for if
if {$result == "something"} {
} else {
}
#executes the command
send "$cmd\r"
#looks for pattern for the result
expect -re "\[#%$].*" {
#$expect_out(buffer) expect variable that stores the output of the command. split this by \r\n to get the result
set dataBuff [split $expect_out(buffer) "\r\n"]
set result [lindex $dataBuff 2]
}
#syntax for if
if {$result == "something"} {
} else {
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2006 08:02 PM
07-03-2006 08:02 PM
Re: Expect If Statement
Lee,
http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.43/man.html also touches on this on Page 11
http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.43/man.html also touches on this on Page 11
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP