The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with linux shell script emachala Shell Programming and Scripting 1 01-26-2009 01:13 AM
GUI shell script for Linux mr_aliagha Shell Programming and Scripting 0 12-05-2008 10:28 AM
how to encrypt my shell script program in linux akm9999 Shell Programming and Scripting 3 09-09-2008 05:30 AM
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 02:55 PM
porting shell script from Linux to AIX. joy_1 Shell Programming and Scripting 6 12-27-2007 02:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-10-2009
wilson735 wilson735 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
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.
  #2 (permalink)  
Old 02-10-2009
ddreggors ddreggors is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 91
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:
Code:
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:

Code:
#!/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:
Code:
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.

Last edited by ddreggors; 02-10-2009 at 01:53 AM..
  #3 (permalink)  
Old 02-10-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,890
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.
  #4 (permalink)  
Old 02-10-2009
wilson735 wilson735 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
Thanks guys, now it seems so simple.
  #5 (permalink)  
Old 02-10-2009
ddreggors ddreggors is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 91
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.
  #6 (permalink)  
Old 02-11-2009
wilson735 wilson735 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
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?
  #7 (permalink)  
Old 02-11-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,890
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0