LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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, 08: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, 08:48 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,446

Rep: Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548
Code:
man xargs
and take a look at -n
 
Old 12-08-2014, 11: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, 04:17 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,340

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
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, 04:19 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,551

Rep: Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251Reputation: 7251
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 06:45 AM
Bash script to move first line to end? mac101 Programming 5 01-10-2012 02:44 AM
bash script to move files except the last 5 dappa Linux - Newbie 4 08-26-2011 03:01 PM
In a bash script, how do I move a line to a new file. wonderfullyrich Programming 18 04-30-2011 12:52 AM
Please, need a bash script move... kukata Programming 3 05-06-2009 12:45 PM

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

All times are GMT -5. The time now is 08:26 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