shell script

jaydip's Avatar, Join Date: Mar 2010
Go4Expert Member
my problem is like this..

when this shellscript run that time it ask a username.. if user not enter username within one minute than it show a msg like time out..... otherwise it display user successfully login...


thanks in advance ....
0
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
Hi, you can use the "read" command with -t option. This would help. Please find the code below.

Code:
#! /bin/sh

echo ""
echo "Program starts..."
echo "Enter the value within 10 seconds..."

read -t 10 input # Here -t followed by 10 means, the command will wait for 10 seconds to get the input.

if [ -z $input ]
then
    echo "Timed out. Please try again..."
else
    echo "Successfully logged in..."
fi
echo ""

Last edited by venami; 13May2010 at 10:36.. Reason: Adding comments to the code.