Hello Monks!
I want to convert a bash script to Perl which i know is very CPU and time consuming.
(it is sa-learn which gunzips old quarantined items and feeds it to spamassassin for spam relearning see end for details)
I read of Devel::DProf in another post, but since i know already which part of the script is worst, (its the whole thing :-)) this wont be useful here.
I am wondering if i could do:
Insert sleep some seconds in the loop?
Stop the script (and continue later if this is possible?) if CPU consumption is e.g. more than 30%
(So it would only run if the machine is nearly idle and wont interrupt the other users?)
How could i determine the cpu consumption like linux command sar (Package sysstat)?
What would you suggest, your thoughts?.
Thanks for your ideas in advance.
code of original bash script:
cat spamlearn_old.sh
#!/bin/sh
for f in `ls /var/lib/amavis/virusmails/spam*.gz`; do
echo Learn Spam-Mails from File $f ...
gzip -cd $f | sudo -u amavis -H sa-learn --spam --showdots;
done
Update:
I tried to start the script with a low nice priority,
reniced it, but it wont help much, forgot this to mention ...
/Update
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.