Register
It is currently Tue Sep 23, 2014 10:25 pm

script to automatically delete temporary files on shutdown.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Tue May 27, 2008 10:04 pm   

Joined: Tue May 27, 2008 9:56 pm
Posts: 3
Location: Escanaba, Michigan
I am in my first class on linux and I have to create a script that will automatically delete temporary files upon shutdown. I have been working on this for over a week and I am lost. Once I have the script written I have to write an 8 page paper describing what each line of the script does and how this process will help an administrator. So far I have learned that the temporary files are located in /var/tmp and /tmp but I have no idea on how to write the script. I have seen some examples that I have found online, but they don't make sense. I just came across this forum and will look through it to see if I can grasp an understanding of what I am doing. Any help would be much appreciated.


Top
 Profile  
 PostPosted: Wed May 28, 2008 10:35 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
An 8 page paper? That sounds like [admin edit] a ridiculous assignment [/admin edit], I really hope you didn't pay anything for that class. The script would probably be about 3-4 lines long. Including whitespace.


Top
 Profile  
 PostPosted: Wed May 28, 2008 4:34 pm   

Joined: Tue May 27, 2008 9:56 pm
Posts: 3
Location: Escanaba, Michigan
Should I use crontab to run the script to automate this script? Here is what I have figured out so far, but I am far from knowing what I am doing. So if someone can point me in the right direction it would be helpful.

#!/bin/bash

# this script will automatically remove temporary files upon shutdown

rm -r /tmp

rm -r /var/tmp

I know that this is wrong, do I have to name the files to be deleted, also should I be using if, then, etc. statements in this script. Any suggestions?


Top
 Profile  
 PostPosted: Thu May 29, 2008 10:06 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
hey dodowg,

if you are to do it on shutdown... i would suggest placing the script in the rc.X section of the /etc tree... that way once run level 0 or run level 6 are called on it will be ran (or just make symbolic links to the script in that area)

as far as naming the files to be deleted, sounds like the teacher is being vague. in which case either ask the teacher, or just submit something generic (i personally would ask the teacher, though they will probably just say it doesn't matter).

not all scripts have to use if,then, etc... scripts are just a group of commands to run in sequence, to help limit the redundancy of typing in a long list of commands over and over.

as far as whether or not something is wrong... if it works without feedback from the command line (without feedback means you don't have to type in anything after your command... like a "y" for the "are you sure you want to remove file: xyz") then the script should be just fine. if the command gives feedback... it would still probably be ok... it would just require input to finish... which isn't ideal for a script... as it takes away the point of automation.

hope this helps you onto the right path!


Top
 Profile  
 PostPosted: Thu May 29, 2008 10:09 pm   

Joined: Tue May 27, 2008 9:56 pm
Posts: 3
Location: Escanaba, Michigan
Ok I have the first part of my script configured but like you all stated it way to short to write an 8 page paper on. So my professor said that I might want to tar the files in a backup archive. This is what I have so far.

#!/bin/bash
#This script will automatically delete temporary files
rm -rf /tmp/*
rm -rf/var/tmp/*
exit

* 18 * * 1-5 /home/mnaylor/myscript.sh Using this crontab the script should run at 6 p.m. monday thru friday

So now I have to figure out how to tar the files in a backup archive any suggestions would be much appreciated.


Top
 Profile  
 PostPosted: Fri May 30, 2008 10:40 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
Rather than a cron job, I would either place it in /etc/inittab to run on shutdown, or, depending on your init system, place it in rc.shutdown, or whatever equivalent place. Tarring it would be easy, but another backup option is to use rsync. Personally I think backing up temp files sounds pretty [admin edit] stupid, but if it's what prof wants... Another option for removing temp files is to mount those as "tmpfs", which will make a pseudo-filesystem housed in the system ram, which will obviously be cleared on poweroff.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP