Any key press causing logout from shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Any key press causing logout from shell
# 1  
Old 07-01-2010
Any key press causing logout from shell

Hi all!

I have written a shell script which will invoke perl script infinitly in the background in a loop. Code will do as:Within while loop, perl script will be run in background, get the pid and notify pid in though mail. then wait for pid to be completed before going for next iteration. I am running the shell in background itself.

while [1] do
- invoke perl script in background
- get pid and mial
- wait for pid
- sent mail about job finining
- sleep for some time
done.

Exact Code:
Code:
set +o errexit
while [ 1 ]
do
# enter the optional parameter if we need to
        set -o monitor
        ${HOME}/${PROCESS}.pl ${OPTIONAL} 2>&1 > $LOGFILENAME &
        echo $! > ${PID_DIR}/${PROCESS}.perl
        chmod 755 ${PID_DIR}/${PROCESS}.perl
        cat ${PID_DIR}/${PROCESS}.perl | ${MAIL_BIN} -s "\"${MAIL_HEADING1}\"" ${MAIL_LIST}
        set +o monitor
        wait $!
        cat ${PID_DIR}/${PROCESS}.perl | ${MAIL_BIN} -s "\"${MAIL_HEADING2}\"" ${MAIL_LIST}
        sleep ${SLEEP}
done
exit 0

If run the shell in background then current shell is logging out but shell script and perl scripts are still running in background. Do you see any problem with code? Also I set the 'set +o errexit'. Why the script will exit suddenly? What are the other possible reasons?

Code:
 
misc/script> ./script.sh process1 option1&
[1] 1256
misc/script>
misc/script> exit
/>

Here is the OS info:
Code:
 
misc/script> uname -a
Linux servername 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

Please help what I need to check? it very urgent. I am very new to linux env.
# 2  
Old 07-01-2010
How far does it get?
Is there anything in $LOGFILENAME ?
Do you receive both emails ?

Does it work when invoked in foreground?


Also
If you intend to log out and leave the script running, you need "nohup".

Code:
nohup ./script.sh process1 option1 2>&1 >mylogfilename &


Last edited by methyl; 07-01-2010 at 10:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a command for specific amount of time with an auto key press

Hi, I have been trying to do a small fun project for myself. I want to run a command for 45 seconds. And to get the final output of this command, the script requires I push the "q" key on my keyboard and then the final output file becomes available. I tried the following script. But it... (12 Replies)
Discussion started by: jacobs.smith
12 Replies

2. Shell Programming and Scripting

How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site. My code is : #!/bin/sh #================================================= # PATH defination # ================================================... (2 Replies)
Discussion started by: Shuinvy
2 Replies

3. Shell Programming and Scripting

Press Any Key script sequence using bash - HELP

hi to all. im a newbie in unix shell scripts. i want to make a simple unix shell script using the bash shell that asks a user to press any key after a series of commands, or an x if he wishes to exit. here's a sample script that i made: #!/usr/bin/bash pause(){ /usr/bin/echo "\t\t Press... (3 Replies)
Discussion started by: booghaw
3 Replies

4. Shell Programming and Scripting

C Shell path variable causing very slow shell!?HELP

I am using C Shell MKS Toolkit and I ran into a huge problem when setting up some environment variables.:confused: The csh script that I have as my login script runs fine but very very slow. When I add a directory to my PATH it seems to slow down shell startup and even slow down the commands. ... (0 Replies)
Discussion started by: vas28r13
0 Replies

5. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

6. Shell Programming and Scripting

Trap key press in a script

How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to quit if q is pressed. I have seen the traping the signal , but they give option only for traping the defined interrupt signals. But those does not help me here. (3 Replies)
Discussion started by: praveenbvarrier
3 Replies

7. UNIX for Dummies Questions & Answers

Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble. if ; then clear echo "Sorry, that is an invalid choice!" exit fi I am using a KSH script in... (3 Replies)
Discussion started by: jagannatha
3 Replies

8. Shell Programming and Scripting

Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards. i.e. echo "Press Y to print \c" read YesNo At this point the user has to press the enter key to continue. Is there a way to accept the key press from the... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question