1850399 Members
1873 Online
104054 Solutions
New Discussion

limt user function

 
SOLVED
Go to solution
Michael Allmer
Frequent Advisor

limt user function

I am trying to setup a user so that after they login a script begins automatically. Once this script is done I want to automatically log this user off. I do not want them to be able to breakout of the script while it is running to get to a command prompt.

Any Ideas?
9 REPLIES 9
Patrick Wallek
Honored Contributor

Re: limt user function

Have their login shell call the script that you want to run.

At the beginning of the script do a:

trap "" 1 2 3

At the end of the script do an:

exit

So your script looks like:

# cat /dir/scriptname
#!/usr/bin/sh
trap "" 1 2 3
...
...
...
do your stuff here
...
...
...
exit

The linke in the passwd file would be:

users:*:9999:99:GECOS STUFF:/user/homedir:/dir/scriptname

Raj D.
Honored Contributor

Re: limt user function

Hi Mike ,

Use exit in the end of the script. This will make the user logged off after the script is finished.

Also change the interrupt character like Ctrl+c to something else ,so it willnot break the script. ex : stty intr ^u or something like that ,

Hope this will help ,

cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Michael Allmer
Frequent Advisor

Re: limt user function

Here is what I have set up:
In /etc/passwd
sms:***:111:113:SMS inventory,,,:/home/sms:/home/sms/sh_sm

In sh_sms:
#cat /home/sms/gatherer.s
#!/usr/bin/sh
trap "" 123

/home/sms/gatherer.sh

exit

Once the sms user logged on the script did not run and was at the command prompt.
Patrick Wallek
Honored Contributor

Re: limt user function

Is the script executable? Did you get any errors?

What you have should work provided permissions are correct.
James R. Ferguson
Acclaimed Contributor

Re: limt user function

Hi Mike:

You show the entry in '/etc/passwd' as:

/home/sms/sh_sm

Yet you list the script as if the name is:

/home/sms/sh_sms

...with a trailing "s".

Is that a posting error?

Regards!

...JRF...
Michael Allmer
Frequent Advisor

Re: limt user function

I set the permisions to
-rwxr-r-xr-x sms readonly sh_sms
-rwxr-xr-x sms readonly gatherer.sh

Then I got a error about the trap syntax.

Adjusted the syntax to trap " " 1 2 3


All is working.

Thank you
Michael Allmer
Frequent Advisor

Re: limt user function

JRF

The s was left off when I copied the items over from the term window.

Thank you,
Patrick Wallek
Honored Contributor
Solution

Re: limt user function

Glad its working for you. If you want it to be a bit more secure, I would drop the "world/other" permissions from those files. Make them rwxr-x--- (750 or o-rx for the chmod command). There's probably no reason for them to be world-readable/executable.
Michael Allmer
Frequent Advisor

Re: limt user function

Thank you to all.

Thank you Patrick about setting the correct secuirty, it gave me the sytax error at that point and all is well.