EXPECT Bash Script Error Control


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting EXPECT Bash Script Error Control
# 1  
Old 09-26-2014
EXPECT Bash Script Error Control

Hello Geeks once more,

Thanks for all the help you have been rendering..

I have a script that depends on the output of an expect statement but sometimes the main script misbehaves which I believe is a result of SSH communication error, how can I apply an error control to know whether the EXPECT script is working?

Code:
#!/usr/bin/bash

#### First Data Collection
pdpsub() {
/usr/local/bin/expect /gsn/pdp/pdp_expect $1 > /tmp/$$pdp

##ATTEMPTED ACTIVATIONS____APN
attwebfirst=`cat /tmp/$$pdp | /usr/sfw/bin/ggrep -A 20 "web.net" | grep "pdp-attempted-activation:" | awk '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'
 | sed 's/[^0-9]*//g'`

# 2  
Old 09-26-2014
That really depends on what the expect script is doing and how it works.

Does the expect script return a proper error code?

Also: Whenever you find yourself doing grep | grep | cut | sed | kitchen | sink, it's time to replace the mess with one awk and be done with it.
# 3  
Old 09-26-2014
Simplification using one awk instead of cat, awk, two seds, and two greps:

Code:
VAR=`awk '/dump_mask/ { L=CTX+2 }; ((--L)>0) && /pdp-attempted-activation:/ { sub(/^[ \t]*[^0-9]*/, ""); print $2 }' CTX=20 /tmp/$$pdp`

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bash script + expect

im very happy to back for this forum I have servers with alias of double dns extentions: sample: servera.test.com servera.test1.com serverb.test.com serverb.test1.com I need to login to that severs and executing the set of commands if test.com failed then try to login via... (0 Replies)
Discussion started by: prakash0106
0 Replies

2. Shell Programming and Scripting

Bash script with expect

Dear all Hi I want use expect in bash so that we can not use these with each other /bin/bash. With. /usr/bin/expect How can use these with on script or how can call a script from other script #!/bin/bash clear echo "================================== " echo "Enter your Esxi IP"... (3 Replies)
Discussion started by: Baber
3 Replies

3. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

4. Shell Programming and Scripting

Acces Variable from expect-Script in bash-Script

Hi all, I have a little problem with a expect in a bash Script. The hull of my script: #!/bin/sh ( expect -c ' set a \"eee\"; # the variable a ' ) echo $a; # using the variable out of the expect script I would like to use the variable out of the expect script(in bash),... (3 Replies)
Discussion started by: gandalfthepink
3 Replies

5. Shell Programming and Scripting

Expect script called in loop from Bash Script

Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass). Here is... (0 Replies)
Discussion started by: cbo0485
0 Replies

6. Shell Programming and Scripting

Help with control flow in a Bash script

In my bash script I want to say "if argument 2 is anything except x, y or z, than echo this" (x y and z being words). So my script looks like this: if ] then echo "unrecognized input: $2" fi This usually works but than I also want to say "if argument 2 IS x, y, or z, but argument 4 is... (4 Replies)
Discussion started by: Jrodicon
4 Replies

7. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

8. Shell Programming and Scripting

Alternate to SLEEP for EXPECT within BASH script?

Fairly new to the System Admin world, and this is my first post here, hoping to get some clarification. I am using a BASH script to automate some Logfile Archiving (into .tars). The actual logfiles are accessed through an SSH, so I have used the following EXPECT sub-script within my main BASH... (8 Replies)
Discussion started by: Goatfarmer03
8 Replies

9. Shell Programming and Scripting

expect in bash script

Hi, I'm writing a shell script that calls a few commands that prompt the user for two simple yes/no questions. if the answers are consistent (the first is a yes, the second is a no), what would my expect script look like? Google is only giving me answers for scripts where I telnet or ssh. right now... (3 Replies)
Discussion started by: js741
3 Replies

10. 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
Login or Register to Ask a Question