[ubuntu-uk] Login/Logout Scripts
Andrew Oakley
andrew at aoakley.com
Mon May 5 23:51:36 BST 2008
Rob Beard wrote:
> We'd also like a script to run at logoff to reset the users password (so
> they can't just log back on for another hour without asking first). For
> this I was thinking of a script to reset the password using passwd.
...
> I see in /etc/gdm there are two directories call PostLogin and
> PostSession, has anyone actually used these?
Yes, me.
/etc/gdm/PostLogin/default is called directly after graphical LOGIN
before the graphical session starts (ie. it is a login script)
/etc/gdm/PostSession/Default is called directly after graphical LOGOUT.
I use /etc/gdm/PostLogin/Default to erase and re-create (from tar.gz) my
guest account on my laptop, so that well-meaning but annoying geek
friends who insist on "improving" the guest desktop setup, have their
efforts wiped at the next subsequent login.
You sound like you want /etc/gdm/PostSession/Default instead.
In case you also want to wipe and re-create the entire account, I have
supplied my /etc/gdm/PostLogin/default , /usr/local/bin/loadguest and
/usr/local/sbin/saveguest scripts too. They are public domain.
> as root after login, so I wonder if I could run my autologoff script
> from there and at the end of the autologoff script have a line that
> resets the password? (I presume any scripts executed from the Default
> script will run as root too?)
Yes and yes.
Consider chown root.root and chmod 750 to prevent the users cat'ing the
script to discover the password.
--
Andrew Oakley
===== /etc/gdm/PostLogin/Default =====
#!/bin/bash
if [[ "$LOGNAME" == "guest" ]]
then
/usr/local/bin/loadguest
fi
===== /usr/local/bin/loadguest =====
Note that you can supply a parameter, the username. If absent it assumes
"guest". Remember to chmod 755 this script.
#!/bin/bash
# Goes in /etc/gdm/PostLogin/Default
# This script erases & re-creates a user home directory that has
# previously been saved with saveguest
username=$1
if [[ "$username" == "" ]]
then
username=guest
fi
if [[ -f /home/$username.tar.gz ]]
then
cd /home
rm -rf $username/*
tar xvfz /home/$username.tar.gz
else
echo "/home/$username.tar.gz does not exist or is not a regular file"
fi
===== /usr/local/sbin/saveguest =====
Note the s in sbin! Must be RUN AS ROOT once you have set up the account
the way you like it AND LOGGED OUT OF THAT ACCOUNT (if you don't log
out, nasty things are left lying around like xauthority). Remember to
chmod 755 this script.
Note that you can supply a parameter, the username. If absent it assumes
"guest".
#!/bin/bash
username=$1
if [[ "$username" == "" ]]
then
username=guest
fi
if [[ -d /home/$username ]]
then
cd /home
mv -f $username.tar.gz $username-old.tar.gz
tar cvfz $username.tar.gz $username
else
echo "/home/$username does not exist or is not a directory"
fi
More information about the ubuntu-uk
mailing list