Linux Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux Shell Script
# 1  
Old 02-10-2009
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  
Old 02-10-2009
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 02:53 AM..
# 3  
Old 02-10-2009
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  
Old 02-10-2009
Thanks guys, now it seems so simple.
# 5  
Old 02-11-2009
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  
Old 02-11-2009
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  
Old 02-11-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need some Help please with Linux shell script.

we need help with the syntax with this shell script, if you could create this shell script we can donate to a charity etc. we need to set up a directory called user3 inside directory user3 we need to create the following files : afile, anyfile, anotherfile, afiletest, bfile. bfiletest, cfile,... (3 Replies)
Discussion started by: cometboy
3 Replies

2. Shell Programming and Scripting

Script Shell Linux

Hello, Please, how can I complete this script: Thank you (2 Replies)
Discussion started by: chercheur857
2 Replies

3. Homework & Coursework Questions

Linux Shell Script

Hi Guys I am new to Linux Shell Scripting . Can any one help me with this Task...files are attached for reference Task 1: write a script to generate a large size report file MX0002_new.XML by using the template MX0001_new.XML. Shell script is recomended, and it can run on Linux without... (2 Replies)
Discussion started by: samy_1811
2 Replies

4. Shell Programming and Scripting

Need help! Linux shell script

Hi all, I am trying to make a Nodemanager work in RHEL 5 I got this script from 'oraclemiddleware.wordpress.com', and made appropriate changes to suit my weblogic installation. I keep getting the error, "line 82: syntax error: unexpected end of file". I have checked every line to make sure all... (4 Replies)
Discussion started by: chakrv1
4 Replies

5. Homework & Coursework Questions

LINUX Bash Shell Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a bash shell script that presents work information of employees of a department from a company data... (1 Reply)
Discussion started by: help123
1 Replies

6. Shell Programming and Scripting

PLEASE HELP! LINUX BASH SHELL SCRIPT

PLEASE HELP! NEED LINUX SCTIPT Need to write a bash shell script to show information of employees of a department from a company data set. The script should accept a project number (1/2/3/10/20/30) and output * the name of the project * the name of the manager of the controlling... (1 Reply)
Discussion started by: help123
1 Replies

7. Shell Programming and Scripting

Shell Script for ping, Linux

I woul like to create a script in order to make a ping to a server and save in a variable a 1 if respond or a 0 if it doesnt. Then with that I could make a graffic of the server, for how long it is up.:b: So far I have this: if ; then #if the ip respond the ping shows online echo... (3 Replies)
Discussion started by: jsebastiang0
3 Replies

8. Shell Programming and Scripting

help with linux shell script

HI im a novice with shell scripts but i need help with a random script I have this folder filled with 500 different file names... I need help creating a script that will take each filename and make a new folder named that filename and then move that file into the newly created folder. Then the... (1 Reply)
Discussion started by: emachala
1 Replies

9. Shell Programming and Scripting

GUI shell script for Linux

Hi, I want to write shell script file that have a GUI with multiple input box for user entry , i mean multiple input box in one dialog ( window) not one window for each entry , i tried kdialog , and zenity , i didnt find a way to have multiple input box in one window with zenity and kdialog.... (0 Replies)
Discussion started by: mr_aliagha
0 Replies

10. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies
Login or Register to Ask a Question