Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Im trying to acomplish a particular task with the (newly discovered for me) Touch utility.
here is my objective:
I have created a directory on my SUSE9.0 box - internal users and external clients/subcontractors/etc will use this directory for quick get/put file exchanges... external users will copy files to the directory via FTP (have vsftpd installed and configured), internal users connect to the directory via samba (also installed and working).
For security reasons, managment has insisted that files be automatically deleted after aproximately 2 days/ 48 hours. I have come up with a script that will delete files with a modified/created date older than 2 days, but I still have a problem.
When copied to the directory, whether by ftp or samba, the files are retaining thier original create/modified date. Therefore the above noted script will delete, essentially, any file every time it is run.
Someone suggested that I use TOUCH to modify the datestamp. I came up with the idea to run TOUCH once a night (say at 11:58 pm) to modify all new files with the current days datestamp, then a minute later run my script to delete all files older than 48 hours. Users could be told that the files would stay for 2 callendar days.
HERE IS MY DILEMMA: I cant figure out how to instruct TOUCH to only modify files it has not previously modified. Otherwise all files will get the current days datestamp, and nothing will ever get autodeleted. Ive tried the -c option... it doenst work.
Im really hoping that someone can give me the exact syntax to try - im a brand newbie - Ive copied the man pages for touch below.
Someone please help..
Update the access and modification times of each FILE to the current time.
Mandatory arguments to long options are mandatory for short options too.
change only the access time
Modify the time by going back SECONDS seconds. For example, touch -r foo -B 5 bar will make the file bar 5 seconds older than file foo.
do not create any files
parse STRING and use it instead of current time
Modify the time by going forward SECONDS seconds. For example, touch -r foo -F 5 bar will make the file bar 5 seconds newer than file foo.
change only the modification time
use this file's times instead of current time
use [[CC]YY]MMDDhhmm[.ss] instead of current time
set time given by WORD: access atime use (same as -a) modify mtime (same as -m)
display this help and exit
output version information and exit
Note that the -d and -t options accept different time-date formats.
I think it was me who replied to your original post before, I actually made a script up before that did it but ya'd gone (although not going the extra step of taking into count files being delete by users in between runs)
touch all the files
Do a directory listing and save it into a file
at whatever time needed do another directory listing and save it
compare the two files in this case using comm -3 file1 file2 > differences
use the contents of differences to touch only new files that have appeared
cron job sorts out the 2 day bit
A wee bit of round-robin deleting/renaming the files that contain the directory listing and the process starts again
i dont know if you want to do this but you could try making a hidden file with the same name as the real file after you have edited its timestamp and then in the script check if a .(dot) file with that name exists,for example if your file is foo you can create a .foo by doing touch .foo and then when you check...just look for .foo..then dont mess with it else...go ahead and change its timestamp.
i dont think this should use up too much space since the file will be 0 bytes.
my 2 cents
Looking_Lost - I included your original post below...
I definately will need some help getting started on the script... in particular how to dump a directory listing to a file (sorry folks - im very exp in the computer world, but VERY new to the linux planet). Im assuming that COMM is the command to compare a pair of files... in what context/what syntax would this be used to tell touch to only modify files that are the difference of the compare?
any complete or partial help would be greatly appreciated!!!
I guess you could have a file containg a directory listing taken at time A and compare it against a file containing the current directory listing taken at time B and use directly/send the output to another file which should contain the differences. If and buts start coming in though to complicate matters such as can the users delete the file themselves inbetween runs? The principle is there though to work around though and maybe some one will jump in with a one line does it all answer
comm -3 timeA timeB > differencesInListings
Originally posted by t3___ oh... and rmanocha... if I went your direction....
how exactly would I tell touch to both:
touch a file/modify it's date stamp,
create the hidden file?
how would I instruct touch to NOT modify files with a twin hidden file?
well maodify the date stamp as usual and then just take the filename(i believe you can rip it off ...i am not really an authority in bash scripting) and append a .(dot to it)
checking for the hidden file should be easy....again rip the filename of the file and then use the if command with the -f(i think it is) to check if there is a similar file name with a .(dot) appended to it.
i know i am not answering your question but this is the best i can do now...i can try to write the script...if and when i get time.
btw... Newcastle, not Guiness, is the best beer in the world
well actually it is carlsberg who goes by this ad(and that beer is great too) but i personally think guisness kicks everyones a**es.but that could just be me.never tried newcastle...maybe i should give it a try...which county is it from?
Okay, I had another go at it, try this. Change the values of ftpDir and workingDir appropriately. Save it as filetoucher.sh and make it executable ensuring that your workingDir exits. Run it once from the command line as
after that you can run it in a cron job like
it should touch only those files that have been created since the last touch aswell as taking into account any files deleted by users in between runs the -1 parameter passed to comm should ensure that. Give it a whirl anfd let me know how it does as I don't have the time/or patience to sit creating/deleting files to test it absolutely fully.
ftpDir="/var/lib/ftp" #set this to your ftp directory
workingDir="/home/myhome" #set this to the directory to hold the temp files in
for i in `ls $ftpDir`
ls $ftpDir > $workingDir/lastListing
ls $ftpDir > $workingDir/currentListing
comm -1 -3 $workingDir/lastListing $workingDir/currentListing > $workingDir/differences
for i in `cat $workingDir/differences`
mv $workingDir/currentListing $workingDir/lastListing
case $1 in
echo $"Usage: $0 init|update"
Last edited by Looking_Lost; 02-05-2004 at 03:54 PM.
looking lost - ok. I tested the script file you wrote above - first off, THANK YOU SO MUCH FOR YOU HELP!
It appears to not be working.
When I run the command, the output is the following:
Usage: /srv/scripts/testscript.sh initlupdate
I can be certain that I specified the ftp and working directory properly. I have only a basic understanding of these bash scripts, but I can say for certian that the script is NOT dumping the directory listing to the working dir, and is not touching any of the files.