Jump to content

Script for logging out


Recommended Posts

Ok.. all of you script gurus out there, (that includes you Aru :deal: ) I need a bash script for this situation.

 

Let's say I make an account called guest so that any people can login using that account. Now I want that during logout (that is logging out using the K-menu since the machine is running on init level 5) it will execute the following commands.

 

1. Erase everything in the /home/guest directory

2. Copy some files and directories (like e-mail or browser information, kde configuration, etc) from say a /usr/share/guest directory to /home/guest with all the permission put in the correct order.

 

So the purpose of this script is to restore everything just like the first time the user login using guest account. This will be useful for say a temporary terminal.

 

So the questions are:

 

1. What is the script that can do this?

2. Where should I put the script and how to execute it automatically during user logout.

 

Thanks in advance.

Link to comment
Share on other sites

1. What is the script that can do this?

2. Where should I put the script and how to execute it automatically during user logout.

 

A couple of things you should take into account before doing anything:

 

NEVER TRUST GUESTS, so a script owned by guest is discarted (IMHO), that means that nothing put on .bashrc, ..., .bash_logout, or the kde initscripts equivalents, should be used.

Another place to put this stuff is within kdm, gdm... scripts which are owned and run by root, but that makes complicated to maintain them because there are many chances that an update will overwrite them.

 

So, you should find out a way to aware root that the guest user logs-out. I would suggest some watchlog software that launches the script when matches the logout event in the system logs. For example in /var/log/messages it could be something like:

Apr 13 12:34:33 mandrakeusers login(pam_unix)[3128]: session closed for user guest

I don't remember any watchlog program right now, but I've used some in the past, so they exist. :jester: Ofcourse you may find another way to achieve the same as always happens in linux.

 

 

...So when that event is produced (and the logout is registered) the script will be launched to do (this is what I'd do):

  1. Remove the full "guest" account, including its home directory. As I've said never trust guests (he/she might have had the temptation of change something vital that make your approach unusable (ie change the guest password))
     
     
  2. Add again the user guest from scratch, you might have at this point a full working skeleton dir for the guest user which might contain all the files the guest visitor may need and what you wanted (e-mail or browser information, kde configuration, etc). So the skeleton directory will be used by adduser when creating the home dir. (man adduser, there explains how to use the -k flag). Also at this point you have to provide the guest password

 

Basically this can be done by:

ACCOUNT=guest

SKELETON_DIR=/var/guestaccount/ # this dir has all the stuff to build the /home/guest

 

# first check that the users (non system) account "guest" exists:

# users accounts in mandrake have an uid > 500!!!

if awk -F ':' "\$1 ~ /$ACCOUNT/ {if (\$3 > 500) OK=1} END { if (OK!=1) exit 1}" /etc/passwd;

then

# no account guest exists

exit 0

fi

 

 

# 1st remove the account

userdel -r $ACCOUNT

 

# 2nd create the account from the skeleton and set password

useradd -m -k $SKELETON_DIR $ACCOUNT &&\

echo "guestpassword" | passwd --stdin $ACCOUNT

 

 

 

 

 

The above code is not tested, so I suggest you to check all with its options using the man pages ;)

 

 

 

HTH, and here I am if you have more questions

Link to comment
Share on other sites

Wow.. aru himself answer my question.. cool :)

 

Anyway, what you suggest is what I have in mind. The problem is just implementing it (making the script and putting it, etc). Thanks for confirming my belief.

 

Now.. for there is a program called logwatch, I found it at http://www.logwatch.org Do you think this can be the solution for watching the logs?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...