Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Let me save you $10

Kymermosst (33885) writes | more than 7 years ago

The Internet 5

I was browsing around freshmeat and found this little gem of a shareware program.

Here's the scoop from the description page. For only $10 you get:

General:

* Delete ALL files (in the specified directory) with file dates older than the specified days.
* For Unix/Linux system only.

I was browsing around freshmeat and found this little gem of a shareware program.

Here's the scoop from the description page. For only $10 you get:

General:

        * Delete ALL files (in the specified directory) with file dates older than the specified days.
        * For Unix/Linux system only.

Features:

        * E.g. Delete all files older than 30 days - regardless of the permission setting of the files.
        * Can be run manually from browser, telnet or automatically using crontab.
        * Support deletion of files in multiple folders and of different ages.
        * Only two variables to edit - the directory and the file age.

Requirement:

        * Perl
        * No MySQL needed.
        * No SSI needed.

Here's what they are charging $10 for. Only they've written it in perl.

--- BEGIN CUT HERE ---
  #!/bin/sh
  DIR=/path/to/directory
  AGE=30
  find $DIR -mtime +$AGE -exec rm -f {} \;
--- END CUT HERE ---

Only two variables to edit, deletes everything in the specified directory (DIR) older than AGE days. You can even do multiple directories with different ages by deleting the DIR= and AGE= and copying the find command a few times, substituting the values in for $DIR and $AGE. You can run it as-is from telnet, and from cron, and by adding "echo Content-type: text/plain ; echo" at the top, it might even run as CGI.

Oh, and you can have the above for free. But if you want to send me $10 for all 10 seconds that took to write, be my guest.

cancel ×

5 comments

Sorry! There are no comments related to the filter you selected.

Moo (1)

ncc74656 (45571) | more than 7 years ago | (#17822284)

With its reputation for enabling code that is barely distinguishable from line noise, Perl is the perfect choice for such an app...if you're trying to sell it. It makes it harder for the unwashed masses to tell just how badly you've just ripped them off. :-)

Subject (1)

nmb3000 (741169) | more than 7 years ago | (#17822340)

Yes, but do you offer lifetime free upgrades & support? :)

Re:Subject (1)

Kymermosst (33885) | more than 7 years ago | (#17824788)

If I ever think of a way to do it more efficiently and produce a new version, I'll be sure to post it in my journal...

On a more serious note (1)

ncc74656 (45571) | more than 7 years ago | (#17822376)

find $DIR -mtime +$AGE -exec rm -f {} \;

I frequently want to do something (could be anything) to the files listed by a find command. I've usually done something like for i in `find ...`; do ... $i; done, but that chokes if the filenames returned by find include spaces or certain other characters. I didn't know there was an option to have find run arbitrary commands with its output, and it looks like it handles all filenames properly. Sweet!

Re:On a more serious note (1)

Kymermosst (33885) | more than 7 years ago | (#17824776)

I know a few more find tricks. I use Samba to serve files, several Windows clients connect. Check out my incremental virus scan of /home using F-prot for Linux workstations [f-prot.com] (free as in beer)... only scans directories that changed since yesterday:

#!/bin/sh
SCANBASE=/home
SCANDATE=`date +"%D"`
if [ -x /usr/local/f-prot/tools/check-updates.pl ]; then
        UPDATE=`/usr/local/f-prot/tools/check-updates.pl -cron`
        if [ -n "$UPDATE" ]; then
                echo "$UPDATE" | /bin/mail -s "Virus Definitions Updated: $SCANDATE" root
        fi
fi
# This version only scans the contents of changed directories since the
# beginning of yesterday.
# This reduces scan time and avoids scanning large numbers of files
# that have not changed recently.
umask 077
TEMPFILE=`/bin/mktemp -t .vscan.XXXXXXXX` || exit 1
if [ -x /usr/local/bin/f-prot ]; then
/usr/bin/find $SCANBASE -daystart -mtime -2 -type d -fprint0 $TEMPFILE
        if [ -s $TEMPFILE ]; then
/bin/cat $TEMPFILE | /usr/bin/xargs -0 /usr/local/bin/f-prot -type -wrap -nosub | /bin/mail -s "Virus Scan Results (daily): $SCANBASE $SCANDATE" root
        fi
fi
/bin/rm $TEMPFILE
I run this out of cron on a daily basis. It downloads virus updates before starting the scan.

This correctly feeds the list of directories to F-prot and accounts for spaces, etc. It uses a few tricks, including getting find to output a file containing null-terminated strings and getting xargs to read them. It also demonstrates the correct way to create a temporary file in a shell script (assuming you have mktemp, which almost any *nix should have these days).

I run this one weekly on Sundays:

#!/bin/sh
SCANBASE=/home
SCANDATE=`date +"%D"`
if [ -x /usr/local/f-prot/tools/check-updates.pl ]; then
        UPDATE=`/usr/local/f-prot/tools/check-updates.pl -cron`
        if [ -n "$UPDATE" ]; then
                echo "$UPDATE" | mail -s "Virus Definitions Updated: $SCANDATE" root
        fi
fi
if [ -x /usr/local/bin/f-prot ]; then
/usr/local/bin/f-prot -wrap -type $SCANBASE | mail -s "Virus Scan Results (full): $SCANBASE $SCANDATE" root
fi
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>