Jonathan Nichols am Montag, 21. November 2005 01.48:
> First off, I'm lousy with Perl.
> That being said, everything in the script works except for the few lines
> that I've commented out, and the second to last line, where I try to
> remove the files that are in the shared-maildir spam drop box. I've
> tried quotes, full path names, backticks, everything that I can think
> of, but the results end up being the same.
>
> Help?
>
> The script:
>
> [EMAIL PROTECTED] ~/bin $ cat eat_spam.pl
> #!/usr/bin/perl
> #
> # Just a script to gather up spam, tar it up,
> # and move it over to mailgate for further
> # processing.
> #
> # Friday, May 13th, 2005.
> #
> use warnings;
>
> # define some variables
> $spambucket = "/home/vmail/shared-maildirs/Spamdrop/.Incoming/cur";
> $canofspam = "spam.tar";
> # die if $canofspam is already there
> # die "$canofspam already exists, exiting...\n" if (-f "$canofspam");
> #if (-e "$canofspam") {
> #system("tar -cf $canofspam $spambucket");
> #} else {
> print"Creating the tarball...\n";
> system("tar -rf $canofspam $spambucket");
> print"Created the tarball...\n";
> system("chown jnichols:users $canofspam");
> print"Changed permissions on $canofspam...\n";
> system("scp $canofspam [EMAIL PROTECTED]:~/");
> print"Moved $canofspam to mailgate...\n";
> system("rm $canofspam");
> system("ls $spambucket | while read f; do sudo rm \$f; done");
> print"Removed old spam from $spambucket";
>
> The results, and some stuff I've tried:
>
> [EMAIL PROTECTED] ~/bin $ ./eat_spam.pl
[snipped long cmdline session]

Hello Jonathan,

In addition to Mariusz' post, I have a general remark:

Your Script is in perl, but all the actual work is done by the shell.
This means a lot of forking processes.
Also, the script get's longer if you, as you should, check if the system 
commands terminated successfully.

I think the best way would be to write this script entirely in bash. 
It would be shorter, more elegant, and faster i think.

On the other hand, you could use functionality from perl instead of forking 
shells and write the script in perl only. But this would be more complicated 
than a shell script (using perl commands for removing files and file 
listings etc.; modules for tar and scp.

Just some thoughts,

joe
-- 
[email protected] mailing list

Reply via email to