1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

shell script

Discussion in 'Unix' started by jaydip, May 3, 2010.

  1. jaydip

    jaydip New Member

    Joined:
    Mar 29, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    -
    Location:
    bangalore
    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 ....:mad:
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    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 [COLOR=Blue]# Here -t followed by 10 means, the command will wait for 10 seconds to get the input.[/COLOR]
    
    if [ -z $input ]
    then
        echo "Timed out. Please try again..."
    else
        echo "Successfully logged in..."
    fi
    echo ""
    
     
    Last edited: May 13, 2010

Share This Page