Time out in shell script for a stament/line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time out in shell script for a stament/line
# 1  
Old 10-02-2007
Lightbulb Time out in shell script for a stament/line

Folks,
In shell script, can I mention a timeout for a command execution, afterwhich I want to exit from that particular line and proceed furthur.

I have part of my script as below:
******************************
cd $EXPECT_HOME
expect custom_install.exp mv $QA_HOME/install_run/logs/task*.xml $QA_HOME/install_run/logs/console

.....and so on...

********************************

Problem I am cing is, its hanging at the end of Expect script execution..
I just wanna comeout of that after say 2 mins and proceed.
(Expect time out in expect script doesnt work for me somehow).
So, from shell script, can I handle it somehow?

Thanks for ur time.

--Venkat.
# 2  
Old 10-02-2007
Place an 'exit' at the point in the script where you need to exit.

If you need, place an exit code (eg: 'exit x' - where x = 0-?? ).
And then subsequent scripts can execute based on the exit code issued.

Hope I got your query right & it helps some. Smilie

Cheers,
Cameron

Last edited by Cameron; 10-02-2007 at 12:55 AM.. Reason: poor typing & bad eye sight ;-)
# 3  
Old 10-02-2007
Thanks Cameron.
But the problem is my script is not coming out of that expect call.
exit inside expect is not working for me.

I just want to comeout of expect call after 2 mins and proceed furthur in my shell script..


Anymore thoughts?

Thx in advance.
# 4  
Old 10-02-2007
You would need to

spawn a child process which captures it's pid
spawns another child process which does sleep followed by kill of that pid
set up a trap handler
spawn another child process to exec the command capturing the pid of that process
wait for the exec child to finish
clear that pid variable
in the trap handler, if the pid variable is still set then kill that pid
if the killer child has not finished, kill it

alarming?
# 5  
Old 10-02-2007
Show us your expect script. Looks like you may not coded it to
include timeouts or EOF situations Expect can hang on timeout
if waiting for a particular pattern but receives EOF instead.
# 6  
Old 10-02-2007
Thanks guys.

Murphy, yes..better I should code my expect script correct.
Below is the peace of code @ the end of my .exp script.

******************************************

expect "*Next\]> "
sleep 3
expect -timeout 30 "*Exit\]> "
sleep 5
send -- "Exit\r"
send -- "\r"
sleep 3
send -- "\r"
sleep 3
send -- "exit\r"
sleep 5
Exit
##send -- "Next\r"
sleep 3
send -- "exit\r"
sleep 3
Exit 0
send -- "Exit\r"
sleep 3
exit 0
expect "*Exit\r]> "
sleep 5
exit 0
send -- "Exit\r"
sleep 3
exit

*********************************

I simply placed so many exits, hoping atleast 1 will click.
(I m a newbie in Expect scripting Smilie)

and my script simply hangs on..after successful execution.

Thanks for your time.
--Venkat.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

3. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

4. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

7. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

8. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

9. Shell Programming and Scripting

problem with nested if stament

hi everybody: could anybody tell me what I'm doing wrong. I've tried to nest if staments like this: if condition1]; then if condition2];then if condition3];then commands else commands fi elif condition4];then commands... (3 Replies)
Discussion started by: tonet
3 Replies
Login or Register to Ask a Question