|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to Exit a shell script if no input is available for 10 seconds
Hi All, I am a new user to this forum and this is my first request. I have a script which i am calling from crontab, i modified the code to execute directly also. I added an if condition to get user interaction in the code.This is now making the crontab call to wait for input and each time it creates new background process. Code:
var=`find $FILENAME -newer $TIMESTAMP`
echo " Variable is $var Filename is $FILENAME" >> $LOG_HOME/log.txt
if [ "$var" == "" ]
then
echo "No new file available for build, Do you want to continue (Y/N) ? "
read Choice
if [ $Choice == "Y" ]
then
var=1
fi
fiI want to terminate (exit) the script if there is no response to the read command for 10 seconds.Can someone help me with this I am using AIX and i don't have read -t option as given in one of the threads. Last edited by mkarthikeyan82; 04-25-2012 at 09:53 PM.. Reason: code tags please! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
if [[ -z $var ]]
then
read -p "No new file available for build, Do you want to continue (Y/N)? " choice
if [[ $choice == "N" || $choice == "n" ]]
then
exit 0
fi
fi |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
thanks Murphy, But i m getting the following error Code:
./monitor.sh[43]: read: 0403-039 No query process for pipe. Line 43 is Code:
read -p "No new file available for build, Do you want to continue (Y/N) ? " choice Also i need the read command to wait for 10 secs before timingout. ---------- Post updated at 10:59 PM ---------- Previous update was at 10:16 PM ---------- go it ... a rather simple approach...Its working fine.Thanks murphy in helping me out. Code:
#!/bin/ksh TMOUT=5 # TMOUT is an Internal Variable # If the $TMOUT environment variable is set to a non zero value time, then the shell prompt will time out after $time seconds.This will cause a logout. # If you run this script in current shell after 5 seconds you will be logout echo " You only have $TMOUT seconds\n Enter your name quickly: \c" name="" read name if [ ! -z "$name" ] then echo " Your name is $name" else echo -e "\n TIME OUT\n You failed to enter your name" fi
Last edited by Scrutinizer; 04-26-2012 at 03:40 AM.. |
|
#4
|
|||
|
|||
|
You can test whether you are in background and take different action (like not asking the question): Code:
if [ -t 1 ]
then
echo "In foreground"
else
echo "In background"
fi |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| execute the shell script per ten seconds | AKB48 | Shell Programming and Scripting | 6 | 03-09-2012 08:15 AM |
| shell script that will automatically check if specifed user is log in or not, in 30 seconds | gurmad | Shell Programming and Scripting | 2 | 11-26-2009 11:06 PM |
| Exit script if the user dosent enter any data within 5 seconds | frozensmilz | Shell Programming and Scripting | 3 | 03-18-2009 03:30 AM |
| exit script if user input not four characters | ajp7701 | Shell Programming and Scripting | 2 | 10-30-2008 05:48 PM |
| wait for 5 seconds in shell script | gopsman | Shell Programming and Scripting | 2 | 08-30-2007 05:47 AM |
|
|