On Nov 20, 2005, at 5:48 PM, Jonathan Nichols wrote:

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?

Might try comp.lang.perl.misc or perl.beginners? perlmonks.org? perldoc.perl.org?

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;

always: use strict;
Especially if you're having a problem :)
# 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";
If you do end up using the system() function, usually use single quotes to prevent unexpected interpolation/clobbering. I'd do something like this (I'm not a perl nut, so this might be bad style, but should work)

opendir (DH, $spambucket);
my @files = readdir DH;
foreach (@files) {
        unlink;
}

you might also want to look at perldoc -f chdir, unlink, readdir, opendir etc. Also, your question would probably be most welcome on the mailing lists, since you have written code, tried things, etc. What I'm saying is that if you post this to c.l.p.misc or perl.beginners, you'd probably get some quick help as your question isn't "write me a script that does x" (which a lot of them are, to the aggravation of all listmembers =] )
The results, and some stuff I've tried:

[EMAIL PROTECTED] ~/bin $ ./eat_spam.pl
Creating the tarball...
tar: Removing leading `/' from member names
Created the tarball...
Changed permissions on spam.tar...
spam.tar                     100%   50KB  50.0KB/s   00:00
Moved spam.tar to mailgate...
rm: cannot remove `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S' : No such file or directory rm: cannot remove `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S' : No such file or directory rm: cannot remove `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,': No such file or directory rm: cannot remove `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S ': No such file or directory rm: cannot remove `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,': No such file or directory rm: cannot remove `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,': No such file or directory rm: cannot remove `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S': No such file or directory rm: cannot remove `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,': N o such file or directory Removed old spam from /home/vmail/shared-maildirs/ Spamdrop/.Incoming/[EMAIL PROTECTED] ~/bin $ [EMAIL PROTECTED] ~/bin $ ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur
1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
[EMAIL PROTECTED] ~/bin $ for i in 'ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur';do 'sudo rm $i'; done
-bash: sudo rm $i: command not found
[EMAIL PROTECTED] ~/bin $ for i in 'ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur';do sudo rm $i; done
rm: cannot remove `ls': No such file or directory
rm: cannot remove `/home/vmail/shared-maildirs/Spamdrop/.Incoming/ cur': Is a directory
[EMAIL PROTECTED] ~/bin $ ls
add_email.sh add_virtual.sh clear_up_spam.sh eat_spam.pl sqlbackup.sh
[EMAIL PROTECTED] ~/bin $ cd ..
[EMAIL PROTECTED] ~ $ ls
bin  mail_sql.tar  serversidefilter-1.5-1.2.7-RC1.tar.gz  sqlback
[EMAIL PROTECTED] ~ $ cd bin
[EMAIL PROTECTED] ~/bin $ ls
add_email.sh add_virtual.sh clear_up_spam.sh eat_spam.pl sqlbackup.sh [EMAIL PROTECTED] ~/bin $ ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur
1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
[EMAIL PROTECTED] ~/bin $ for i in 'ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur';do sudo cat $i; done
cat: ls: No such file or directory
cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a directory [EMAIL PROTECTED] ~/bin $ for i in ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur ;do sudo cat $i; done
cat: ls: No such file or directory
cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a directory [EMAIL PROTECTED] ~/bin $ for i in "ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur" ;do sudo cat $i; done
cat: ls: No such file or directory
cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a directory
[EMAIL PROTECTED] ~/bin $ which ls
/usr/bin/ls
[EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do sudo cat $i; done cat: 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S: No such file or directory cat: 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S: No such file or directory cat: 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: N o such file or directory cat: 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S: No such file or directory cat: 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: N o such file or directory cat: 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: N o such file or directory cat: 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S: No such file or directory cat: 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,: No such file or directory [EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do cat $i; done cat: 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S: No such file or directory cat: 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S: No such file or directory cat: 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: N o such file or directory cat: 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S: No such file or directory cat: 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: N o such file or directory cat: 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: N o such file or directory cat: 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S: No such file or directory cat: 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,: No such file or directory [EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do file $i; done 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S: cannot open `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S' (No such file or directory) 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S: cannot open `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S' (No such file or directory) 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: c annot open `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,' (No such file or directory) 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S: cannot open `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S ' (No such file or directory) 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: c annot open `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,' (No such file or directory) 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: c annot open `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,' (No such file or directory) 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S: cannot open `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S' ( No such file or directory) 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,: cannot open `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,' (N o such file or directory) [EMAIL PROTECTED] ~/bin $ ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur
1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
[EMAIL PROTECTED] ~/bin $ ls -laFh /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur
total 49K
drwxrwxrwt  2 vmail vmail  752 Nov 20 16:27 ./
drwxr-xr-t  6 vmail vmail  224 Nov 20 16:27 ../
-rw-r--r-- 1 vmail vmail 2.3K Nov 19 03:03 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S -rw-r--r-- 1 vmail vmail 1.5K Nov 19 04:29 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S -rw-r--r-- 1 vmail vmail 8.3K Nov 19 07:34 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2, -rw-r--r-- 1 vmail vmail 9.9K Nov 19 12:26 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S -rw-r--r-- 1 vmail vmail 1.5K Nov 19 13:12 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2, -rw-r--r-- 1 vmail vmail 2.1K Nov 19 23:00 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2, -rw-r--r-- 1 vmail vmail 2.6K Nov 20 14:31 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S -rw-r--r-- 1 vmail vmail 2.1K Nov 20 16:27 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
[EMAIL PROTECTED] ~/bin $
[EMAIL PROTECTED] ~/bin $ which file
/usr/bin/file
[EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do `/usr/bin/file $i`; done -bash: 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S:: command not found -bash: 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S:: command not found -bash: 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,:: command not found -bash: 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S: : command not found -bash: 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,:: command not found -bash: 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,:: command not found -bash: 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:: c ommand not found -bash: 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,:: command not found [EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do /usr/bin/file $i; done 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S: cannot open `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S' (No such file or directory) 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S: cannot open `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S' (No such file or directory) 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: c annot open `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,' (No such file or directory) 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S: cannot open `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S ' (No such file or directory) 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: c annot open `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,' (No such file or directory) 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: c annot open `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,' (No such file or directory) 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S: cannot open `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S' ( No such file or directory) 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,: cannot open `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,' (N o such file or directory) [EMAIL PROTECTED] ~/bin $ for i in `ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur` ;do '/usr/bin/file $i'; done
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
[EMAIL PROTECTED] ~/bin $ for i in 'ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur';do '/usr/bin/file $i'; done
-bash: /usr/bin/file $i: No such file or directory
[EMAIL PROTECTED] ~/bin $ for i in ls /home/vmail/shared-maildirs/ Spamdrop/.Incoming/cur; do '/usr/bin/file $i'; done
-bash: /usr/bin/file $i: No such file or directory
-bash: /usr/bin/file $i: No such file or directory
[EMAIL PROTECTED] ~/bin $


--
[email protected] mailing list


--
[email protected] mailing list

Reply via email to