Expect help needed .. can i do this ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect help needed .. can i do this ?
# 1  
Old 04-19-2013
Expect help needed .. can i do this ?

hi all,
i need to run expect and get the output into variables so my bash script can make decisions
this is what i get currently


Code:
Please wait while gathering statistics...
   1: 0x60bf83c8 [34]
   2: 0x60bf8d58 [21]
   3: 0x60bf8d80 [22]
*  4: 0x60bf93a0 [57]
*  5: 0x62b0b4e0 [51]
   6: 0x605938a0 [25]
   7: 0x62844c74 [21]
   8: 0x60264f28 [29]
   9: 0x60bfd010 [23]
  10: 0x62b35db8 [22]

i need to read these into variables and then
evaluate these ..and if i find one with * as the first character ( if more than one i try 1 first and then 2nd one )

Can someone please help ?

thanx all

Last edited by Corona688; 04-19-2013 at 06:01 PM..
# 2  
Old 04-19-2013
Seems kind of a vague description to me. Smilie
# 3  
Old 04-19-2013
Ok i will try to explain sorry for the vagueness
i get 10 values back from server
each on one line and numbered 1 to 10
i would like to store them in variables so that i can see if the line has a star in the beginning . i ignore the rest
if it has a star
i would like the values i get back
lets say
Code:
* 4: 0x60bf93a0 [57]

in variables
Code:
VAR1 = 4
VAR2 = 0x60bf93a0
VAR3 = 57

then i run a command locally
system ./check something
and if the result of that is 0
i do
send "get this "value of VAR2"


thanx

Last edited by Corona688; 04-19-2013 at 06:01 PM..
# 4  
Old 04-19-2013
Hmmm.

Dynamic variable names probably aren't a good idea, they'd be extremely difficult to count and even harder to use later. How about an array?

You can cheat and tell bash to split on any characters you don't want from that:

Code:
OLDIFS="$IFS"
        IFS=$' \r\n\t[]:*'
        ARRAY=( $( ./myscript.sh | tail -n +2 ) )
IFS="$OLDIFS"

${ARRAY[0]} would be 4, [1] would be 0x60bf93a0, [2], would be 57, and [3] would be the start of the next one and so forth.

The total size of the array would be ${#ARRAY[@]}
# 5  
Old 04-19-2013
AWESOME !!!
thank you very much
i will test it out

quick ( possibly stupid question ) how do i use the system command and store the value in a variable ?
i have tried set x "system cmd.sh" etc ( many variations
# 6  
Old 04-19-2013
BASH doesn't have a system command... Technically every line acts like a system command Smilie

To put a command's output into a variable, you can do VARIABLE="$( command )" Similar to what I'm doing above, except instead of an array, this puts it in a single string.

Do not put any extra spaces around the equal sign, that will stop it from working.
# 7  
Old 04-19-2013
thanx corona .you guys are Amazingly helpful
much much appreciated .

kind regards

---------- Post updated at 04:19 PM ---------- Previous update was at 04:18 PM ----------

2nd didnt work
CPU="$( ./getcpu )"

echo $CPU


btw getcpu is a small script i have written which returns the cpu value from 1 to 100

Last edited by ExpectHelpNeede; 04-19-2013 at 06:25 PM..
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 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

3. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

4. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

5. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

6. Shell Programming and Scripting

Help needed with expect...(If telnet fails)

Hello I'm working using expect to automate telnet commands...i want to check if telnet fails and in this case...certain message should appear or certain word should be out in a file). Thses are the messages that apeear if telnet fails: Trying 172.16.3.115... telnet: Unable to connect... (0 Replies)
Discussion started by: Hossam_Nox
0 Replies

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

8. Shell Programming and Scripting

Expect: Beginner help with spawn and expect

Hello hello, did a quick search and didn't turn up anything helpful. I've got a book I'm sure has the answers, but I don't think I'll have time to finish it before this all has to work, so here goes~ if this isn't a good place to post and someone could direct me to another forum I'd appreciate... (1 Reply)
Discussion started by: Vryali
1 Replies

9. Shell Programming and Scripting

Help needed in expect scripting.

Hi, I am new to expect scripting and need your help in the following task. I want an expect script to take the commands from an input file and then execute the commands and give the command execution output in an otput file. The command execution part is normal and I did it via script by... (2 Replies)
Discussion started by: Sooryaa
2 Replies

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