If statement in expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement in expect script
# 1  
Old 01-10-2014
Linux If statement in expect script

Hi,

Can anyone please help me with the below script, I'm trying to match the prompt output in "if statement" if it matches then send "y" else send "n" and come out. I'm not sure about the expect syntax. pls help me out.
Code:
#!/usr/bin/expect -f 
set INPUT [lindex $argv 0] 
set timeout 60 
spawn su - xxuser 
expect "#" { send "xx\r" }
expect 
if [[ \W.ABC_ABCD_${INPUT}\s\(\W ]];then { 
send "y\r" } 
else 
{ 
send "n\r" 
} 
expect "#" { send "exit\r" }


Thanks in advance!

Last edited by Franklin52; 01-10-2014 at 07:53 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

Do expect script have "or" statement?

Do expect script have "or" statement? sound like this: expect { "A" or "B" { send "123" } "C" { send "567" } I know expect can separate that to do this expect { "A" { send "123" } "B" { send "123" } "C" { send "567" } } (8 Replies)
Discussion started by: sk860811
8 Replies

5. Shell Programming and Scripting

How to add if statement in expect script

Hi, I am new to expect script and I am having difficulty in adding an if statement into a expect FTP login script. Here is the code: #!/usr/local/bin/expect -f set FTP_SITE set FTP_USER set FTP_PASS set FTP_FILE spawn ftp match_max 100000 expect -exact "ftp> " send -- "open... (1 Reply)
Discussion started by: jrcai
1 Replies

6. Linux

Modify expect script with control statement

Ok, so I have this script that was provided to me by one of the posters on this site. This script seems to be perfect. However, since this is a telnet script, i need to add an if then statement to it but dont know how to do it. What i want to do is to have this script spit out a certain... (3 Replies)
Discussion started by: SkySmart
3 Replies

7. Shell Programming and Scripting

If and else statement with Expect

Hi, I have a script which is logging in to network devices via ssh using expect programming. My problem is that if I do Code: ssh host -l uname It only works if y ssh_config is setup to use Protocol 1,2 and my network device I am trying to connect has ssh 1 but not 2. If the... (0 Replies)
Discussion started by: kminev
0 Replies

8. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

9. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

10. Shell Programming and Scripting

Expect control statement

I am using expect I dont know tcl but trying to use a control statement to send requests from an input file - dont know what I am doing to be honest as I dont know tcl and dont use expect too much... Any help? See below Basically I am opening a telnet session to a server which works fine... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question