LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash script to move spammy mails (https://www.linuxquestions.org/questions/linux-software-2/bash-script-to-move-spammy-mails-4175527672/)

cameleon666 12-08-2014 07:02 AM

Bash script to move spammy mails
 
I am trying to write bash script wich can cleanup my whoole server from spam emails that already are present in my client's folders. I would need this script to do,

Check recursively directory /var/qmail/mailnames/* for array of keywords if files with keyword has been found go two levels up to and move files there.

I have started to write something like this, but it will not work as i need. First thing is that i get Argument list too log.

Code:

grep -lir 'discount' /var/qmail/mailanmes/* | xargs mv -t /var/qmail/

TenTenths 12-08-2014 07:48 AM

Code:

man xargs
and take a look at -n

cameleon666 12-08-2014 10:08 AM

I could not sort it out. It was not problem of an -n parameter. Script was working if there was small amount of files, but wheen it had 80k files in directory it just wasn't doing anything.

chrism01 12-11-2014 03:17 AM

The '*' gets expanded by the shell and hits a size limit.
Consider looping eg using 'for file in $(find var/qmail/mailanmes/ -type f) ...
If speed is really a concern, think about multiple jobs for files starting with different chars and/or use a faster lang like Perl.

pan64 12-11-2014 03:19 AM

what about:
grep -lir 'discount' /var/qmail/mailanmes | xargs mv -t /var/qmail/


All times are GMT -5. The time now is 08:29 AM.