Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a script for users to interact with that will present a few, well defined options for usage. For instance, they will have an option to telnet to a device, ssh to a device and telnet to several other core routers. All is well with the initial usage of the menu, when the user logs in he is presented with the menu and able to interact with it. However, the problem is when they telnet, ssh, etc. they are forked out of the menu and into whatever program they executed.
Is there a way to prevent this behavior? I was thinking that it might be best to write each function into its own shell script, therefore never leaving the initial menu. Any ideas would be appreciated.
The script 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>
}
_Menu
I don't think i was clear enough when i wrote the initial post.
When the user logs in, if they choose option 11, they can access the server through the script with no problem. However, when they are ready to leave the server they went to through the script, it exits out completely. i.e. They lose connection to the initial server as well as the one they initially connected to.
Is there anyway to stop this behavior? Why does it do this?
Scripts are traversed from start to finish, so if a) use replace the login shell with your menu and b) you're not keeping them in a continuous loop like my "select" example or point back to the main function inside a "child" function or follow a child function with calling _Menu, then the script will finish. Logging info from "set -x" debugging should show that.
Last edited by unSpawn; 07-18-2008 at 10:06 AM.
Reason: condition
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.