2014年9月23日 星期二

[Shell Script] How to force user to run a shell script on login and force it on logout in UNIX

Sometime we only allow user to perform restricted action defined by the shell script and do not allow them to access normal command prompt, we can do this as follow:

1. Prepare the shell script (e.g. menu.sh)
2. Add the following in the .profile of the user
trap '' 1 2 3 15 # ignore all these signal (ctrl-c, etc)
SHELL=/bin/sh
export SHELL
menu.sh # the shell script you define to restrict user action
echo "MSG:: This is end of profile"    
exit # Exit when the shell script complete



notes:


- Make sure .profile have correct permission (accessible by user itself).






Evernote helps you remember everything and get organized effortlessly. Download Evernote.

沒有留言:

張貼留言