1754798 Members
3704 Online
108825 Solutions
New Discussion юеВ

delay function in ksh

 
SOLVED
Go to solution
emily_3
Frequent Advisor

delay function in ksh

Hi,

If i want to delay any predefined time (e.g. $TIME) in ksh, what the best way, any command? Thanks.
7 REPLIES 7
Patrick Wallek
Honored Contributor
Solution

Re: delay function in ksh

What do you want to delay? The 'sleep' command will wait for the number of seconds specified before proceeding.


ls -l
sleep 30 ### Delay 30 seconds
ls -l

A. Clay Stephenson
Acclaimed Contributor

Re: delay function in ksh

The sleep command will do for the problem as you describe it but what you may want is a timeout if keyboard input is not forthcoming. You can do this via the line command and specifying an optional timeout.

DELAY=15
XX=$(line -t ${DELAY})
STAT=${?} # capture status of last command
if [ ${STAT} -eq 0 ]
then
echo "Input was read; XX = ${XX}"
else
echo "No input was read; timed out"
fi

This construct will allow a script to wait for an input or take a default action if no input is received.
If it ain't broke, I can fix that.
emily_3
Frequent Advisor

Re: delay function in ksh

Thanks.

It seems command "sleep" can only have fix number argument, and couldn't able to have valuable argument.
Command "line" is ok with valuable argument, but the delay can be interruptted by keyboard.
Is this correct? any other good ideas.

Thanks a lot.
Patrick Wallek
Honored Contributor

Re: delay function in ksh

What exactly are you trying to accomplish? If you explained more precisely what you are trying to do then perhaps we could better help you.
A. Clay Stephenson
Acclaimed Contributor

Re: delay function in ksh

Both the sleep command and the -t argument of timeout will accept a shell variable as an argument; in fact, the command itself couldn't tell the difference between a constant and and variable. It would really help if you described what you want to accomplish. For example, if you wanted to start a command in the background and then be notified when it is finished, that is the job of the shell's builtin "wait" command.
If it ain't broke, I can fix that.
emily_3
Frequent Advisor

Re: delay function in ksh

The environment is that a script is called at the same time by different system. And it seems have some conflict at certain command in the scrip, so I plan to implement different delay time at the very begining of the script by using a valuable for each system.
Just now the scirpt failed because the valuable which sent to the sleep command is empty, so it confused me that sleep cann't follow by a valuable.
now it works. Thanks.
Yogeeraj_1
Honored Contributor

Re: delay function in ksh

hi emily,

the sleep command can take variables as arguments.

below a simple test:

export VAL=30
sleep $VAL



you may wish to post an extract from your script/code that is failing

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)