Operating System - HP-UX
1829883 Members
10741 Online
109993 Solutions
New Discussion

How can I excute a shell script when logout ?

 
SOLVED
Go to solution
sufang
Occasional Contributor

How can I excute a shell script when logout ?

HPUX11.00

thanks
7 REPLIES 7
Dario_1
Trusted Contributor

Re: How can I excute a shell script when logout ?

Hi!!

You can schedule in cron or use the at command.

man crontab

man at

Regards,

DR
Dario_1
Trusted Contributor

Re: How can I excute a shell script when logout ?

Hi!!!

You can use the at command or add a cron entry.

Regards,

DR
sufang
Occasional Contributor

Re: How can I excute a shell script when logout ?

thanks for your answer. but what i need is not a scheduled task. i want to let the shell excute some scipt or application just when a user logout (exit) from the server.




Bill Douglass
Esteemed Contributor

Re: How can I excute a shell script when logout ?

For ksh users, set the commands in .logoutk in the user's home directory.
Suhas_2
Regular Advisor

Re: How can I excute a shell script when logout ?

Hi,
In csh you can configure the .logout file. From there you can call the requisite shell script or you can configure that ".logout" file itself as a shell script.

Alternatively,
Inside your .profile you can call another script, which would wait for the exit of your shell. Once it gets the exit code, it would execute a certain commands. This would be helpful to track root-logins and root-logouts, by sending out an e-mail saying root was logged in at XX:YY Hrs and logged out at ZZ:WW Hrs.

Regards..
Suhas
Never say "Die"
Chris Wilshaw
Honored Contributor
Solution

Re: How can I excute a shell script when logout ?

You can achieve this using the trap command;

trap "your_script" 0

(last character is zero)

eg

>trap "banner LOGOUT" 0
>exit
# ####### ##### ####### # # #######
# # # # # # # # # #
# # # # # # # # #
# # # # #### # # # # #
# # # # # # # # # #
# # # # # # # # # #
####### ####### ##### ####### ##### #

Connection closed.
Bill McNAMARA_1
Honored Contributor

Re: How can I excute a shell script when logout ?

try nohup
It works for me (tm)