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 ?
# 8  
Old 04-19-2013
I don't actually see anything wrong with that, in what way did it not work?

Did the text just go directly to the screen? Maybe it prints to standard error instead of standard output. That's usually reserved for error messages but sometimes you want to catch its output too, and you can:

Code:
VAR=$( command 2>&1 )

# 9  
Old 04-19-2013
can't read "( ./getcpu )": no such variable
while executing
"CPU="$( ./getcpu )""
(file "./test.sh" line 12)


---------- Post updated at 04:28 PM ---------- Previous update was at 04:28 PM ----------


ls getcpu
getcpu

# 10  
Old 04-19-2013
You are running this in BASH, yes? You asked for BASH...
# 11  
Old 04-19-2013
sorry if i misled you

what i have is an expect script that needs to do what i originaly posted
but in the expect script i need to call a bash script ( which gets me the current cpu )
that is called getcpu .. i need to evaluate the value returned by the getcpu script

hope i am clear ?
please ask if not and i will post the script
# 12  
Old 04-19-2013
Apologies for misunderstanding. I thought you were using expect to extract information for BASH, not vice versa.

Unless it's doing something picky and interactive like automatic telnet logins, I'm not sure what you're using expect for; it's meant to automate interactive things, to the point it comes with autoexpect -- a tool that generates expect programs, just from watching what you type when you run something. For general scripting, expect's it's not so great.

Please post your code, certainly.
# 13  
Old 04-20-2013
corona ,
funnily enough thats exactly what i am trying to do ..automate the manual process
i run a server which spikes the cpu to 100%
but you can reduce it by setting a value
which can be gotten using a command
so my expect script "should " loolk like this

Code:
#!/usr/bin/expect -f
spawn telnet server port
expect "started"
send "get value server"
// this when i get the response back , and i need to find the lines , returned with a * in the beginning
cpu=getcpu 
while  cpu > 90 
do
send "value1 "
done


once it gets the correct value applied , the cpu drops to 10-15 %
which is what i need to be done via an expect script , i can do it manually like i said

thanx


this is the code for my gecpu
Code:
#!/bin/bash
read cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
CPU=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
echo $CPU
exit $CPU


Last edited by Corona688; 04-22-2013 at 04:33 PM..
# 14  
Old 04-28-2013
Sorry to bump this , its been a week
can anyone help ?
all i am trying to find out is
in an expect script
how can i store the value returned by another ( bash) script

i want to call the bash script using system or exec and evaluate the response and send some other commands based on that


PLEASE help

---------- Post updated at 06:12 AM ---------- Previous update was at 06:06 AM ----------

Got it Smilie
man just needed to google correctly
Code:
set variable [ exec cmd ]


Last edited by Franklin52; 05-01-2013 at 03:37 AM..
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