LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-08-2014, 07:02 AM   #1
cameleon666
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Rep: Reputation: 0
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/
 
Old 12-08-2014, 07:48 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,461

Rep: Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552
Code:
man xargs
and take a look at -n
 
Old 12-08-2014, 10:08 AM   #3
cameleon666
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 12-11-2014, 03:17 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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.
 
Old 12-11-2014, 03:19 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

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


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script to move files from date cbing Programming 9 04-20-2012 05:45 AM
Bash script to move first line to end? mac101 Programming 5 01-10-2012 01:44 AM
bash script to move files except the last 5 dappa Linux - Newbie 4 08-26-2011 02:01 PM
In a bash script, how do I move a line to a new file. wonderfullyrich Programming 18 04-29-2011 11:52 PM
Please, need a bash script move... kukata Programming 3 05-06-2009 11:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration