1 |
Jonathan Nichols am Montag, 21. November 2005 01.48: |
2 |
> First off, I'm lousy with Perl. |
3 |
> That being said, everything in the script works except for the few lines |
4 |
> that I've commented out, and the second to last line, where I try to |
5 |
> remove the files that are in the shared-maildir spam drop box. I've |
6 |
> tried quotes, full path names, backticks, everything that I can think |
7 |
> of, but the results end up being the same. |
8 |
> |
9 |
> Help? |
10 |
> |
11 |
> The script: |
12 |
> |
13 |
> jnichols@mail ~/bin $ cat eat_spam.pl |
14 |
> #!/usr/bin/perl |
15 |
> # |
16 |
> # Just a script to gather up spam, tar it up, |
17 |
> # and move it over to mailgate for further |
18 |
> # processing. |
19 |
> # |
20 |
> # Friday, May 13th, 2005. |
21 |
> # |
22 |
> use warnings; |
23 |
> |
24 |
> # define some variables |
25 |
> $spambucket = "/home/vmail/shared-maildirs/Spamdrop/.Incoming/cur"; |
26 |
> $canofspam = "spam.tar"; |
27 |
> # die if $canofspam is already there |
28 |
> # die "$canofspam already exists, exiting...\n" if (-f "$canofspam"); |
29 |
> #if (-e "$canofspam") { |
30 |
> #system("tar -cf $canofspam $spambucket"); |
31 |
> #} else { |
32 |
> print"Creating the tarball...\n"; |
33 |
> system("tar -rf $canofspam $spambucket"); |
34 |
> print"Created the tarball...\n"; |
35 |
> system("chown jnichols:users $canofspam"); |
36 |
> print"Changed permissions on $canofspam...\n"; |
37 |
> system("scp $canofspam jnichols\@192.168.10.3:~/"); |
38 |
> print"Moved $canofspam to mailgate...\n"; |
39 |
> system("rm $canofspam"); |
40 |
> system("ls $spambucket | while read f; do sudo rm \$f; done"); |
41 |
> print"Removed old spam from $spambucket"; |
42 |
> |
43 |
> The results, and some stuff I've tried: |
44 |
> |
45 |
> jnichols@mail ~/bin $ ./eat_spam.pl |
46 |
[snipped long cmdline session] |
47 |
|
48 |
Hello Jonathan, |
49 |
|
50 |
In addition to Mariusz' post, I have a general remark: |
51 |
|
52 |
Your Script is in perl, but all the actual work is done by the shell. |
53 |
This means a lot of forking processes. |
54 |
Also, the script get's longer if you, as you should, check if the system |
55 |
commands terminated successfully. |
56 |
|
57 |
I think the best way would be to write this script entirely in bash. |
58 |
It would be shorter, more elegant, and faster i think. |
59 |
|
60 |
On the other hand, you could use functionality from perl instead of forking |
61 |
shells and write the script in perl only. But this would be more complicated |
62 |
than a shell script (using perl commands for removing files and file |
63 |
listings etc.; modules for tar and scp. |
64 |
|
65 |
Just some thoughts, |
66 |
|
67 |
joe |
68 |
-- |
69 |
gentoo-server@g.o mailing list |