Find the answer to your Linux question:
Results 1 to 10 of 10
Hi all How to write script file to choice and run command? I mean Display Menu 1. nslookup 2. ping 3. reboot 4. poweroff 0.exit I want to logout current ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    15

    script menu file

    Hi all

    How to write script file to choice and run command?

    I mean Display Menu

    1. nslookup
    2. ping
    3. reboot
    4. poweroff

    0.exit

    I want to logout current user when press 0.

    Best Regards
    Please

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    For example:


    echo "1) Option 1"
    echo "2) Option 2"
    echo "3) Option 3"
    echo ""
    read ACCION

    case $ACCION in

    1)
    echo "option 1 selected!"
    ;;
    2)
    echo "option 2 selected!"
    ;;
    3)
    echo "option 3 selected!"
    ;;

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    15
    Hi thanks for your configuration

    How can I deny ctrl key for that script?
    that script was exit when press ctrl-c or ctrl z.
    I want to protect from this key.

    Please help me again

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    for building menus you can use "select"
    Code:
    man bash
    then look for select (select is a bash built-in)


    for controlling signals you can use "trap"
    Code:
    man trap
    NOTE - there are some signals you can not trap
    Linux and me it's a love story

  5. #5
    Just Joined!
    Join Date
    Dec 2008
    Posts
    15
    HI Thanks for your advice but I did not get ideal.

    If you can ,please help me

  6. #6
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    this is how you can use trap
    Linux and me it's a love story

  7. #7
    Just Joined!
    Join Date
    Dec 2008
    Posts
    15
    Hi

    Thanks for your reply

    Is it?

    if [ ! -e $lockfile ]; then
    trap "rm -f $lockfile; exit" INT TERM EXIT
    touch $lockfile
    critical-section
    rm $lockfile
    trap - INT TERM EXIT
    else
    echo "critical-section is already running"
    fi


    If OK pls guide to me how to add this code in My script because of now I need urgent
    that is why

    I am hoping for your help

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    pls guide to me how to add this code in My script
    We haven't seen your script yet.

    Surely you didn't expect us to write the script for you? That won't help in the long run. You need to scroogle the following search terms:
    Code:
    bash tutorial
    I need urgent
    We're not impolite, just busy writing our own scripts. :) When you have a script, and it doesn't work, and you have a specific question about why it doesn't work, we'd be glad to help.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  9. #9
    Just Joined!
    Join Date
    Dec 2008
    Posts
    15
    Hi
    Following is my script
    Please Edit


    #!/bin/bash
    # A menu driven Shell script which has following options
    # Contents of /etc/passwd
    # List of users currently logged
    # Prsent handling directory
    # Exit
    # As per option do the job
    # -----------------------------------------------
    # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
    # This script is licensed under GNU GPL version 2.0 or above
    # -------------------------------------------------------------------------
    # This script is part of nixCraft shell script collection (NSSC)
    # Visit Bash Shell Scripting Directory For Linux / UNIX for more information.
    # -------------------------------------------------------------------------

    while :
    do
    clear
    echo " M A I N - M E N U"
    echo "1. nslookup"
    echo "2. bwm-ng"
    echo "3. Reboot"
    echo "4. PowerrOff"
    echo "0. Exit"
    echo -n "Please enter option [0 - 4]"
    read opt
    case $opt in
    1) echo "************ nslookup *************";
    nslookup;;
    2) echo "*********** bwm-ng ";
    bwm-ng;;
    3) echo "Press [enter] for reboot";
    reboot;;
    4) echo "Press [enter] for Shut Down";
    poweroff;;
    0) echo "EXIT";
    logout;;
    *) echo "$opt is an invaild option. Please select option between 1-4 only";
    echo "Press [enter] key to continue. . .";
    read enterKey;;
    esac
    done

    Thanks

  10. #10
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    It looks like you've done everything except actually fill in the individual items.

    The next step is to do these things at the command line:
    Code:
    man nslookup
    man ping
    man 8 shutdown
    Then do the "trap dance", as previously suggested, and you're there.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...