Linux-Noob Forums
Meun based shell - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: How Do I? (https://www.linux-noob.com/forums/forum-60.html)
+--- Thread: Meun based shell (/thread-891.html)



Meun based shell - magikman - 2008-07-17


Howdy,

 

 

 

I am writing a shell script for users with no knowledge of UNIX. The script will be used as their shell and will give them options on things to do/execute. I need to allow them to telnet, ssh, etc. to devices. The following is what i have so far:

 



Code:
#!/bin/sh
#set -x
user=`whoami`;
CLEAR=`which clear`;
TELNET=`which telnet`;
MENU=/usr/local/query/menu;
SSH=`which ssh`;

_Menu ()
{
    $CLEAR;
    echo " "
    echo "        ============================================================"
    echo "                                 NS2 MENU                           "
    echo "        ============================================================"
    echo "           1. Telnet to a Device          12. CMTS Intfc Modem Count"
    echo "           2. SSH to a Device             13. Ping/Traceroute Device"
    echo "           3. Clear SSH Known Hosts       14.  "
    echo "           4. Access Core1 GSR            15.  "
    echo "           5. Access Core2 GSR            16.  "
    echo "           6. Access Core3 VXR            17.  "
    echo "           7.                             18.  "
    echo "           8.                             19.  "
    echo "           9.                             20.  "
    echo "          10.                             21.  "
    echo "          11. Access Server             22.  "
    echo "        ============================================================"
    echo "                    Select a Menu Number Option      "or"           "
    echo "                 Type  H# for Help on a Menu Option  "or"           "
    echo "                        --Q  to Quit Menu--                         "
    echo "        ============================================================"
    echo -n "Enter Menu Option ======> "
    read option;

    case "$option" in

            1)
                    _telnet;
           ;;

            2)
                    _ssh;
           ;;

            3)
                    _clearssh;
           ;;

            4)
                    _core1;
           ;;

            5)
                    _core2;
           ;;

            6)
                    _core3;
           ;;

            11)
                    _aov;
           ;;

            12)
                    _mdmcnt;
           ;;

            13)
                    _pingtrace;
           ;;

            *)
                    $CLEAR;
                    echo -e "You chose an invalid response. Please try again.\n Press any key to continue.";
                    read junk;
                    $MENU
           ;;

            esac
}

_telnet ()
{
    $CLEAR;
    echo -n "Enter IP address of device and press Return: ";
    read host;
    $TELNET $host;
}
_ssh ()
{
    $CLEAR;
    echo -n "Enter IP address of deivce and press return: ";
    read host;
    $SSH $host
}

_clearssh ()
{
    $CLEAR;
    echo -e "Know hosts has been cleared.\n Press any key to continue.";
    read junk;
    $MENU;
}

_core1 ()
{
    $CLEAR
    $TELNET <someIP>

}
_core2 ()
{
    $CLEAR
    $TELNET <someIP>
}
_core3 ()
{
    $CLEAR
    $TELNET <someIP>
}
_aov ()
{
    $CLEAR
    $SSH 216.54.59.140
}
_Menu




 

The problem i am having is that after remoting into another box, i lose the shell script as the shell when they come back. If anyone has any suggestions, i am all ears (znx).




Meun based shell - anyweb - 2008-07-18


if i was writing a script like this in windows (batch file) i'd use a call statement to 'call' another command (like ssh) and once it is completed it returns control to the original script

 

dunno how to do that in linux though,




Meun based shell - hybrid - 2008-07-18


I'm not sure if this would work, and can't verify it right now, but wouldn't it work to just call your internal menu procedure after finishing the external command?

 

Such as...

 



Code:
_ssh ()
{
    $CLEAR;
    echo -n "Enter IP address of deivce and press return: ";
    read host;
    $SSH $host
    _Menu
}




 

According to http://www.unix.com/shell-programming-scri...nal-script.html, control should be returned to your script after running the external command, so you just need to catch that and push them back to the menu, in theory.




Meun based shell - magikman - 2008-07-21

Yes, calling the menu again will work.