- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Scripting Problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2008 12:32 AM
01-05-2008 12:32 AM
#! /bin/ksh
main ()
{
tput clear
echo "\t************************** WELCOME ****************************** \n"
echo "\t\t\t 1.top\n"
echo "\t\t\t 2.bdf\n"
echo "\t\t\t 3.syslog\n"
echo "\t\t\t 4.log shipment\n"
echo "\t\t\t x.exit\n"
echo "\t***************************************************************** \n"
echo "\t Enter your choice: \c"
read input
case $input in
1) /usr/bin/top -d 1 ;;
2) /usr/bin/bdf ;;
3) /usr/bin/tail -10 /var/adm/syslog/syslog.log ;;
4) /usr/bin/ll /earch3a/edc_sb ;;
*) exit 0 ;;
esac
}
while (true)
do
main
done
The Script works fine. But upon giving exit, it exits and comes to the prompt, but what i am looking for is to get exited from the server completely. And anywhere in between the script, if i give ctrl+c, even then the prompt comes up.
I want to avoid hapenning this.
Kindly help!!
Thanks in Advance!!
Sridhar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2008 12:56 AM
01-05-2008 12:56 AM
Re: Scripting Problem
If you want to exit completely on control C, you need to add a trap:
trap 'echo "doing exit"; exit' 2
- Tags:
- exec
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2008 01:44 AM
01-05-2008 01:44 AM
Re: Scripting Problem
But i want to know where should i put these two lines in the script.
Kindly let me know!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2008 06:12 AM
01-05-2008 06:12 AM
SolutionAs Dennis noted, add a 'trap' to catch the 'Ctrl_C' signal. The 'exec scriptname' would be placed in the last line of your login profile, like:
exec /home/shridar/menu.sh
Then, as soon as you login, your script runs. When the script exits, you are also logged off the server. Your script would look like the following. Notice that I added a prompt and a read for keyboard input at the end of the 'case' execution. You want the user to be able to see your output!
#!/usr/bin/sh
trap 'echo "doing exit"; exit' 2
main ()
{
tput clear
echo "\t************************** WELCOME ****************************** \n"
echo "\t\t\t 1.top\n"
echo "\t\t\t 2.bdf\n"
echo "\t\t\t 3.syslog\n"
echo "\t\t\t 4.log shipment\n"
echo "\t\t\t x.exit\n"
echo "\t***************************************************************** \n"
echo "\t Enter your choice: \c"
read input
case $input in
1) /usr/bin/top -d 1 ;;
2) /usr/bin/bdf ;;
3) /usr/bin/tail -10 /var/adm/syslog/syslog.log ;;
4) /usr/bin/ll /earch3a/edc_sb ;;
*) exit 0 ;;
esac
echo "Press RETURN to continue"
read REPLY
}
while (true)
do
main
done
Regards!
...JRF...
- Tags:
- profile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2008 07:27 AM
01-05-2008 07:27 AM
Re: Scripting Problem
If you want a certain user to always run this set of commands, you can change this user's login shell in /etc/passwd to specify the script instead of /usr/bin/sh or /usr/bin/ksh. Now the script will be the login process and when complete, will close the session. This is a common way to prevent shell access and only provide a menu for restricted users.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2008 09:06 PM
01-06-2008 09:06 PM
Re: Scripting Problem
Thanks once again.
Sridhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2008 09:14 PM
01-06-2008 09:14 PM
Re: Scripting Problem
Got the solution that i expected.