Gentoo Archives: gentoo-server

From: Sam Halicke <tuscantwelve@×××××.com>
To: gentoo-server@l.g.o
Subject: Re: [gentoo-server] Help me with a perl script..
Date: Mon, 21 Nov 2005 17:42:57
Message-Id: 2584396D-B09E-4A72-8F04-59FD3D8F84D9@gmail.com
In Reply to: [gentoo-server] Help me with a perl script.. by Jonathan Nichols
1 On Nov 20, 2005, at 5:48 PM, Jonathan Nichols wrote:
2
3 > First off, I'm lousy with Perl.
4 > That being said, everything in the script works except for the few
5 > lines that I've commented out, and the second to last line, where I
6 > try to remove the files that are in the shared-maildir spam drop
7 > box. I've tried quotes, full path names, backticks, everything that
8 > I can think of, but the results end up being the same.
9 >
10 > Help?
11 >
12 Might try comp.lang.perl.misc or perl.beginners? perlmonks.org?
13 perldoc.perl.org?
14
15 > The script:
16 >
17 > jnichols@mail ~/bin $ cat eat_spam.pl
18 > #!/usr/bin/perl
19 > #
20 > # Just a script to gather up spam, tar it up,
21 > # and move it over to mailgate for further
22 > # processing.
23 > #
24 > # Friday, May 13th, 2005.
25 > #
26 > use warnings;
27 >
28 always: use strict;
29 Especially if you're having a problem :)
30 > # define some variables
31 > $spambucket = "/home/vmail/shared-maildirs/Spamdrop/.Incoming/cur";
32 > $canofspam = "spam.tar";
33 > # die if $canofspam is already there
34 > # die "$canofspam already exists, exiting...\n" if (-f "$canofspam");
35 > #if (-e "$canofspam") {
36 > #system("tar -cf $canofspam $spambucket");
37 > #} else {
38 > print"Creating the tarball...\n";
39 > system("tar -rf $canofspam $spambucket");
40 > print"Created the tarball...\n";
41 > system("chown jnichols:users $canofspam");
42 > print"Changed permissions on $canofspam...\n";
43 > system("scp $canofspam jnichols\@192.168.10.3:~/");
44 > print"Moved $canofspam to mailgate...\n";
45 > system("rm $canofspam");
46 > system("ls $spambucket | while read f; do sudo rm \$f; done");
47 > print"Removed old spam from $spambucket";
48 If you do end up using the system() function, usually use single
49 quotes to prevent unexpected interpolation/clobbering.
50 I'd do something like this (I'm not a perl nut, so this might be bad
51 style, but should work)
52
53 opendir (DH, $spambucket);
54 my @files = readdir DH;
55 foreach (@files) {
56 unlink;
57 }
58
59 you might also want to look at perldoc -f chdir, unlink, readdir,
60 opendir etc.
61 Also, your question would probably be most welcome on the mailing
62 lists, since you have written code, tried things, etc. What I'm
63 saying is that if you post this to c.l.p.misc or perl.beginners,
64 you'd probably get some quick help as your question isn't "write me a
65 script that does x" (which a lot of them are, to the aggravation of
66 all listmembers =] )
67 > The results, and some stuff I've tried:
68 >
69 > jnichols@mail ~/bin $ ./eat_spam.pl
70 > Creating the tarball...
71 > tar: Removing leading `/' from member names
72 > Created the tarball...
73 > Changed permissions on spam.tar...
74 > spam.tar 100% 50KB 50.0KB/s 00:00
75 > Moved spam.tar to mailgate...
76 > rm: cannot remove
77 > `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S'
78 > : No such file or directory
79 > rm: cannot remove
80 > `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S'
81 > : No such file or directory
82 > rm: cannot remove
83 > `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,':
84 > No such file or directory
85 > rm: cannot remove
86 > `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
87 > ': No such file or directory
88 > rm: cannot remove
89 > `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,':
90 > No such file or directory
91 > rm: cannot remove
92 > `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,':
93 > No such file or directory
94 > rm: cannot remove
95 > `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S':
96 > No such file or directory
97 > rm: cannot remove
98 > `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,': N
99 > o such file or directory
100 > Removed old spam from /home/vmail/shared-maildirs/
101 > Spamdrop/.Incoming/curjnichols@mail ~/bin $
102 > jnichols@mail ~/bin $ ls /home/vmail/shared-maildirs/
103 > Spamdrop/.Incoming/cur
104 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
105 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
106 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
107 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
108 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
109 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
110 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
111 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
112 > jnichols@mail ~/bin $ for i in 'ls /home/vmail/shared-maildirs/
113 > Spamdrop/.Incoming/cur';do 'sudo rm $i'; done
114 > -bash: sudo rm $i: command not found
115 > jnichols@mail ~/bin $ for i in 'ls /home/vmail/shared-maildirs/
116 > Spamdrop/.Incoming/cur';do sudo rm $i; done
117 > rm: cannot remove `ls': No such file or directory
118 > rm: cannot remove `/home/vmail/shared-maildirs/Spamdrop/.Incoming/
119 > cur': Is a directory
120 > jnichols@mail ~/bin $ ls
121 > add_email.sh add_virtual.sh clear_up_spam.sh eat_spam.pl
122 > sqlbackup.sh
123 > jnichols@mail ~/bin $ cd ..
124 > jnichols@mail ~ $ ls
125 > bin mail_sql.tar serversidefilter-1.5-1.2.7-RC1.tar.gz sqlback
126 > jnichols@mail ~ $ cd bin
127 > jnichols@mail ~/bin $ ls
128 > add_email.sh add_virtual.sh clear_up_spam.sh eat_spam.pl
129 > sqlbackup.sh
130 > jnichols@mail ~/bin $ ls /home/vmail/shared-maildirs/
131 > Spamdrop/.Incoming/cur
132 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
133 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
134 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
135 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
136 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
137 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
138 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
139 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
140 > jnichols@mail ~/bin $ for i in 'ls /home/vmail/shared-maildirs/
141 > Spamdrop/.Incoming/cur';do sudo cat $i; done
142 > cat: ls: No such file or directory
143 > cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a
144 > directory
145 > jnichols@mail ~/bin $ for i in ls /home/vmail/shared-maildirs/
146 > Spamdrop/.Incoming/cur ;do sudo cat $i; done
147 > cat: ls: No such file or directory
148 > cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a
149 > directory
150 > jnichols@mail ~/bin $ for i in "ls /home/vmail/shared-maildirs/
151 > Spamdrop/.Incoming/cur" ;do sudo cat $i; done
152 > cat: ls: No such file or directory
153 > cat: /home/vmail/shared-maildirs/Spamdrop/.Incoming/cur: Is a
154 > directory
155 > jnichols@mail ~/bin $ which ls
156 > /usr/bin/ls
157 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
158 > Spamdrop/.Incoming/cur` ;do sudo cat $i; done
159 > cat:
160 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S:
161 > No such file or directory
162 > cat:
163 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S:
164 > No such file or directory
165 > cat:
166 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: N
167 > o such file or directory
168 > cat:
169 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S:
170 > No such file or directory
171 > cat:
172 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: N
173 > o such file or directory
174 > cat:
175 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: N
176 > o such file or directory
177 > cat:
178 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:
179 > No such file or directory
180 > cat:
181 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,:
182 > No such file or directory
183 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
184 > Spamdrop/.Incoming/cur` ;do cat $i; done
185 > cat:
186 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S:
187 > No such file or directory
188 > cat:
189 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S:
190 > No such file or directory
191 > cat:
192 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: N
193 > o such file or directory
194 > cat:
195 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S:
196 > No such file or directory
197 > cat:
198 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: N
199 > o such file or directory
200 > cat:
201 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: N
202 > o such file or directory
203 > cat:
204 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:
205 > No such file or directory
206 > cat:
207 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,:
208 > No such file or directory
209 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
210 > Spamdrop/.Incoming/cur` ;do file $i; done
211 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S:
212 > cannot open
213 > `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S'
214 > (No such file or directory)
215 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S:
216 > cannot open
217 > `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S'
218 > (No such file or directory)
219 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: c
220 > annot open
221 > `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,'
222 > (No such file or directory)
223 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S:
224 > cannot open
225 > `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
226 > ' (No such file or directory)
227 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: c
228 > annot open
229 > `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,'
230 > (No such file or directory)
231 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: c
232 > annot open
233 > `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,'
234 > (No such file or directory)
235 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:
236 > cannot open
237 > `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S' (
238 > No such file or directory)
239 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,:
240 > cannot open
241 > `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,' (N
242 > o such file or directory)
243 > jnichols@mail ~/bin $ ls /home/vmail/shared-maildirs/
244 > Spamdrop/.Incoming/cur
245 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
246 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
247 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
248 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
249 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
250 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
251 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
252 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
253 > jnichols@mail ~/bin $ ls -laFh /home/vmail/shared-maildirs/
254 > Spamdrop/.Incoming/cur
255 > total 49K
256 > drwxrwxrwt 2 vmail vmail 752 Nov 20 16:27 ./
257 > drwxr-xr-t 6 vmail vmail 224 Nov 20 16:27 ../
258 > -rw-r--r-- 1 vmail vmail 2.3K Nov 19 03:03
259 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S
260 > -rw-r--r-- 1 vmail vmail 1.5K Nov 19 04:29
261 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S
262 > -rw-r--r-- 1 vmail vmail 8.3K Nov 19 07:34
263 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,
264 > -rw-r--r-- 1 vmail vmail 9.9K Nov 19 12:26
265 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
266 > -rw-r--r-- 1 vmail vmail 1.5K Nov 19 13:12
267 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,
268 > -rw-r--r-- 1 vmail vmail 2.1K Nov 19 23:00
269 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,
270 > -rw-r--r-- 1 vmail vmail 2.6K Nov 20 14:31
271 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S
272 > -rw-r--r-- 1 vmail vmail 2.1K Nov 20 16:27
273 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,
274 > jnichols@mail ~/bin $
275 > jnichols@mail ~/bin $ which file
276 > /usr/bin/file
277 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
278 > Spamdrop/.Incoming/cur` ;do `/usr/bin/file $i`; done
279 > -bash:
280 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S::
281 > command not found
282 > -bash:
283 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S::
284 > command not found
285 > -bash:
286 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,::
287 > command not found
288 > -bash:
289 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S:
290 > : command not found
291 > -bash:
292 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,::
293 > command not found
294 > -bash:
295 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,::
296 > command not found
297 > -bash:
298 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:: c
299 > ommand not found
300 > -bash:
301 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,::
302 > command not found
303 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
304 > Spamdrop/.Incoming/cur` ;do /usr/bin/file $i; done
305 > 1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S:
306 > cannot open
307 > `1132422567.M220626P10407V0000000000000803I0004F9F5_5.mail,S=2307:2,S'
308 > (No such file or directory)
309 > 1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S:
310 > cannot open
311 > `1132422571.M251371P10407V0000000000000803I0004FA3E_7.mail,S=1455:2,S'
312 > (No such file or directory)
313 > 1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,: c
314 > annot open
315 > `1132422574.M701586P10407V0000000000000803I000503D9_8.mail,S=8450:2,'
316 > (No such file or directory)
317 > 1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S:
318 > cannot open
319 > `1132442174.M698309P21779V0000000000000803I00029BE0_0.mail,S=10100:2,S
320 > ' (No such file or directory)
321 > 1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,: c
322 > annot open
323 > `1132442174.M699069P21779V0000000000000803I0004E35B_1.mail,S=1512:2,'
324 > (No such file or directory)
325 > 1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,: c
326 > annot open
327 > `1132471810.M604970P26258V0000000000000803I00002027_0.mail,S=2098:2,'
328 > (No such file or directory)
329 > 1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S:
330 > cannot open
331 > `1132531951.M353195P662V0000000000000803I0002D413_1.mail,S=2564:2,S' (
332 > No such file or directory)
333 > 1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,:
334 > cannot open
335 > `1132532830.M152462P881V0000000000000803I0003441D_1.mail,S=2113:2,' (N
336 > o such file or directory)
337 > jnichols@mail ~/bin $ for i in `ls /home/vmail/shared-maildirs/
338 > Spamdrop/.Incoming/cur` ;do '/usr/bin/file $i'; done
339 > -bash: /usr/bin/file $i: No such file or directory
340 > -bash: /usr/bin/file $i: No such file or directory
341 > -bash: /usr/bin/file $i: No such file or directory
342 > -bash: /usr/bin/file $i: No such file or directory
343 > -bash: /usr/bin/file $i: No such file or directory
344 > -bash: /usr/bin/file $i: No such file or directory
345 > -bash: /usr/bin/file $i: No such file or directory
346 > -bash: /usr/bin/file $i: No such file or directory
347 > jnichols@mail ~/bin $ for i in 'ls /home/vmail/shared-maildirs/
348 > Spamdrop/.Incoming/cur';do '/usr/bin/file $i'; done
349 > -bash: /usr/bin/file $i: No such file or directory
350 > jnichols@mail ~/bin $ for i in ls /home/vmail/shared-maildirs/
351 > Spamdrop/.Incoming/cur; do '/usr/bin/file $i'; done
352 > -bash: /usr/bin/file $i: No such file or directory
353 > -bash: /usr/bin/file $i: No such file or directory
354 > jnichols@mail ~/bin $
355 >
356 >
357 > --
358 > gentoo-server@g.o mailing list
359 >
360
361 --
362 gentoo-server@g.o mailing list