Make expect exit the UNIX script in erreneous condition
Hi,
I am writing a menu driven program using shell script. THe script will be collecting data by logging into the other servers and bringing back the data to home server to process it and accordingly issue commands. TO automate commands execution , I am using expect script. However I am not able to understand , how to do error handling with expect script
I tried using the code tags . Somehw there is some issue . Hence pasting the code
Last edited by Don Cragun; 12-28-2015 at 03:29 PM..
Reason: Add CODE tags.
Hi,
I am writing a menu driven program using shell script. THe script will be collecting data by logging into the other servers and bringing back the data to home server to process it and accordingly issue commands. TO automate commands execution , I am using expect script. However I am not able to understand , how to do error handling with expect script
I tried using the code tags . Somehw there is some issue . Hence pasting the code
Moderator's Comments:
Look at the tutorial explaining how to use CODE tags in the private e-mail that was sent to you a few minutes ago...
Quote:
If this is a shell and/or expect script, why are you telling the system to use awk to interpret it???
This User Gave Thanks to Don Cragun For This Post:
Sorry for the incomplete code. I had sent fragments of my code and hence only awk was present.
Thank you for using CODE tags correctly.
I'm not sure what you mean by "only awk was present". You do realize that if you invoke the script shown in your last post by name (i.e., ./scriptname where scriptname is the name of the file containing the code you showed us), the only line (of those shown above from the start of your script) that makes any difference in how the script is run, is the first line. Every other line (including: #!/bin/expect -f) is just a comment. And, if you invoke this script by naming the interpreter to run the script and giving the script's name as an operand to that interpreter (i.e. ksh scriptname), every single line shown here is just a comment. (And note that even though the 1st line implies that this script should be executed by bash, running it with ksh scriptname will run the script with ksh; not bash.)
This User Gave Thanks to Don Cragun For This Post:
I got your point Don. Thanks for explaining that.
However I have seen that if I have to use awk in my shell script. I need to mention it to the system with statement
other wise it throws error. I generally run the script as input to the interpreter. Even then awk statements throw an error. Hence I had used it.
Secondly my main query is still not resolved which is in relation to how to fulfill the functional requirement using expect script.
As I have mentioned in the between the code, I want expect to perform 2 operations on observing keyword directory.
1)touch ~/error
2)break from the expect function to execute the if condition.
It breaks from the expect script to check the if condition, however it does not create the error file
Can you help me out with the coding for expect ?
1. Make sure what language you write your script
2. All of the script must be the same language
3. You can call other scripts (files) of other languages, if you really need multiple script languages
Bash, awk and expect are not compatible shebangs to mix the code, though, awk can be invoked as often you like when using bash.
However, you can use neither (afaik) bash nor awk from an expect script.
Aside from that, I dont see any awk invocation in your script at all anyway...
Are you aware that your variable 'FNAME' contains the hardcoded STRING 'command'?
And that you'r asking for an assword, rather than a password, several times?
Last but not least, have to admit i do not 'know' expect - AFAIK, isnt expect to be used so one does not have to pass passwords in plaintext to 'scripts'?
Yet you expect the user to pass his password to the script, which makes expect obsolete in some way.
Please correct me if i'm wrong on this!
Hi All,
Requirement: The below script should automatically exit at 6pm everyday without manually killing the script
Tried running with the below shell script but found the script was still running when the time was 6:15pm. The script did not exit the while loop at 6pm
The script runs... (6 Replies)
We have a requirement where in the user needs to select a option 4 from the menu and the putty window should be closed.I tried giving exit 0 ;; and this is only exiting from the script menu and showing back the prompt.Is there a way for this. (2 Replies)
Hi,
I am using Solaris OS,
I want to handle an occasional expression in expect script while logging into a remote server with ssh.
In normal scenario the expected expression is as below,
spawn ssh $user@$ip
expect "assword:"
send "$password\r"
but in a condition when the remote server... (2 Replies)
All
i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $
#!/usr/bin/expect
set timeout 10
set arg
set arg1
spawn ssh -l UserA 1.1.1.1
expect "assword:";
send "PasSwOrD\r";... (1 Reply)
Hello all, I created the below script....and it seemed to be working fine. My problem is i want the script to ignore rest of the things if my condition is not met but do not exit....
#!/bin/ksh
###########################
###########################
# Set name of the listener, this... (2 Replies)
Hi all,
I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature).
This is confirmed by these posts.
Now I'm trying to launch sipp from an expect script that runs in crontab.
... (0 Replies)
Hi
I am programing a expect script on debian, I connected to a firewall to get configuration copy via telnet or ssh but Because of firewall show configuration console wait and print --More-- need press space key at least 100.Help me please.
firewall output like this :(
This output isn't... (3 Replies)
Hi All,
I am stuch in a script where a for loop is running to execute some commands for some values.
Now my problem is i have to have an if condition that if the first iteration is successful then it has to exit the for loop otherwise it has to continue normally.
my code is this:
for... (5 Replies)
from my main script, i am calling an expect script. there are a lot of conditions in the Expect script and it can have any exit value based on success or failure of the Expect Script. how can i check the exit status of Expect scritp in the main script. (1 Reply)