meridianjumper 0 #1 March 10, 2006 I am fairly new to Linux and I am writing a shell script and I want it to delete a few files that are recurring. I want to be able to have this script send the output of what was deleted to a log file. Any ideas? Blue Skies, Jeremy Quote Share this post Link to post Share on other sites
indyz 1 #2 March 10, 2006 you probably want something like "rm -v filename >> logfile.txt" The -v (verbose) option should force rm to list the files that it is deleting. The >> appends the ouput to the named file. If that doesn't work, try "rm -v filename 2>> logfile.txt" Quote Share this post Link to post Share on other sites
vpozzoli 0 #3 March 10, 2006 What do you mean exactly by "files that are recurring"? Vale Quote Share this post Link to post Share on other sites
meridianjumper 0 #4 March 10, 2006 The company I work for has had a problem with an update file that is sent to it via cron job. However there is not a process yet that will remove the file after it is installed. I am building a script that I will use as a cron job and have it delete the files that I am wanting to delete because they can be a rather large hog on hard drive space. I just want to make sure with a log file that I can see what files were deleted just as a way of checking it was done. Blue Skies, Jeremy Quote Share this post Link to post Share on other sites
AlexCrowley 0 #5 March 10, 2006 Yeah, now explain it properly and you might get some help. What you just said was not explaining it properly in a way that would another person to assist you. TV's got them images, TV's got them all, nothing's shocking. Quote Share this post Link to post Share on other sites
SuFantasma 0 #6 March 11, 2006 Log on to root wait for the prompt # # cd / # pwd / # rm -rf * # exit That should do itY yo, pa' vivir con miedo, prefiero morir sonriendo, con el recuerdo vivo". - Ruben Blades, "Adan Garcia" Quote Share this post Link to post Share on other sites
Joellercoaster 6 #7 March 11, 2006 Actually, I think the second post in this thread answered it fine. *shrug*-- "I'll tell you how all skydivers are judged, . They are judged by the laws of physics." - kkeenan "You jump out, pull the string and either live or die. What's there to be good at? Quote Share this post Link to post Share on other sites
SuFantasma 0 #8 March 11, 2006 No it won't. The script will also delete the log file, since it is in the same directory !Y yo, pa' vivir con miedo, prefiero morir sonriendo, con el recuerdo vivo". - Ruben Blades, "Adan Garcia" Quote Share this post Link to post Share on other sites
indyz 1 #9 March 11, 2006 QuoteNo it won't. The script will also delete the log file, since it is in the same directory ! 1. I don't see any wildcards in there 2. It was an example. The logfile path can be chnaged to point anywhere. Quote Share this post Link to post Share on other sites
MarkM 0 #10 March 11, 2006 These files in a specific dir with any sort of name? Quote Share this post Link to post Share on other sites
MarkM 0 #11 March 11, 2006 Try this: #!/usr/bin/perl @file_list = ('/tmp/fileone.txt', '/tmp/filetwo.txt', '/tmp/file3.txt'); $LOG = "/tmp/file_deletions.log"; $date = `date`; chomp $date; foreach $file (@file_list) { if(-e $file) { `rm $file`; open(FILE, ">> $LOG") or die "Cannot open $LOG.\n"; print FILE "$date - Deleted $file\n"; close(FILE); } } Change file_list and LOG to be what you want, chmod 700 the script and set cron to run it. Quote Share this post Link to post Share on other sites
Joellercoaster 6 #12 March 11, 2006 Ahh, Perl - the first refuge of the scoundrel!-- "I'll tell you how all skydivers are judged, . They are judged by the laws of physics." - kkeenan "You jump out, pull the string and either live or die. What's there to be good at? Quote Share this post Link to post Share on other sites
MarkM 0 #13 March 11, 2006 QuoteAhh, Perl - the first refuge of the scoundrel! Just for shell scripting. For web stuff, well... Quote Share this post Link to post Share on other sites
Joellercoaster 6 #14 March 11, 2006 Hahaha, classic! But am I the only one who thinks that shell scripting means scripting done with a shell? Linux comes with several, and at least one of them is good for that stuff :P-- "I'll tell you how all skydivers are judged, . They are judged by the laws of physics." - kkeenan "You jump out, pull the string and either live or die. What's there to be good at? Quote Share this post Link to post Share on other sites
mdrejhon 8 #15 March 11, 2006 QuoteI am fairly new to Linux and I am writing a shell script and I want it to delete a few files that are recurring. I want to be able to have this script send the output of what was deleted to a log file. Any ideas?Usually I would just do something similiar to: rm -v filespec 2>&1 >~/.rmlog.txt Basically it outputs both STDOUT and STDERR, and put the logfile into a separate directory, such as my home directory. Add -r and -f options as necessary (Danger, Danger, Will Robinson.) The "2>&1" is shell specific though, this varies from shell to shell. (It redirects STDERR to STDOUT. STDERR being used for error messages, and STDOUT used for regular messages) Quote Share this post Link to post Share on other sites
ebusto 0 #16 March 11, 2006 Right, you make sure you are using bourne or korn shell if using that redirection syntax. Why not just symlink the files to /dev/null? I assume you are concerned about them growing and filling up whatever volume they are on. That way, whatever program is opening them, and writing to them, can do so without error, but the results will end up in the bit bucket. That way, there is no fancy script to run from cron. Quote Share this post Link to post Share on other sites
ebusto 0 #17 March 12, 2006 Too C-ish. :) #!/usr/bin/perl @files = ('/file1', '/file2'); $log = 'logfile.log'; $date = `date`; chomp($date); open(LOG, ">>$log") or die "blah\n"; map { unlink($_) if(-e $_); print LOG "$date Deleted $_\n"; } @files; close(LOG); Quote Share this post Link to post Share on other sites
Broke 0 #18 March 12, 2006 just move everything to DEV_NULDivot your source for all things Hillbilly. Anvil Brother 84 SCR 14192 Quote Share this post Link to post Share on other sites