Linux Shell Script

I'm interested in writing a (hopefully) simple Linux Shell Script.
Upon shutdown of the system (or upon reboot), I would like the script to automatically reset any changes made during that session. This includes files saved to the hard disk as well as any configuration changes. I would also like the script to be run only with guest accounts, the administrative account would not have the script run.

Can anyone help me out? I'm not even sure where to start.

As long as guests are unprivileged users that cannot change things outside of their home directory (/home/guest ?) this is relatively simple.

You can make a copy/backup of the freshly created guest user's home directory:

cp -rp /home/guest /home/guest_bak

and on startup remove the guest home directory and copy the backup back into place.

If you made a backup as "/home/guest_bak" (directory not file). Then you can make a script like:

#!/bin/sh

rm -f /home/guest
cp -rp /home/guest_bak /home/guest

Give that script a name like clean_guest.sh, move it to somewhere like /usr/local/bin, make it executable:

chmod +x /usr/local/bin/clean_guest.sh

Call it from inside /etc/rc.local (redhat) or similar init script and now any changes made or files copied will be gone and have a freshly built user home again.

Or, for a more complex case, you could setup your system to use LVM for all partitions and create a snapshot of the filesystem in it's desired state. Then add an script to the shutdown/reboot runlevels (/etc/init.d and /etc/rc.d/rc.{0,6} for most Linux systems) or for startup that resets the disks to this snapshot.

Thanks guys, now it seems so simple.

Nice alternative pludi, we use lvm alot and do snapshots as well. Not sure why that didn't come to mind... must have been tired.

Anyway, that method is a far better solution. Mine was a quick hack really.

One more question guys..

I'm not too familiar with running LVM from a shell script or even setting it up to run on shutdown/reboot/startup. How would the coding for that look like?

An example for an init script can be found at /etc/init.d/skeleton in most distributions.
As for the snapshot, create it first from the shell and modify /etc/fstab to boot from the snapshot instead of the usual partition. Then, in the init script, make sure that all required modules are loaded, remove the old snapshot using lvremove, and create it new, using the same command as on the command line.
A good intro to LVM can be found at The Linux Documentation Project