LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2015, 10:08 AM   #1
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 49

Rep: Reputation: 0
Simple script question: ${LOGFILES}.* not working


This should be a nice and simple one !

I have a script:

Code:
LOGFILES="schedule_download.log schedule_download_AccountancyServices.log schedule_download_FinancialControl.log schedule_download_IncomeCollection.log schedule_download_banner.log manual_download.log manual_download_AccountancyServices.log manual_download_bacs_cheques.log manual_download_FinancialControl.log manual_download_IncomeCollection.log manual_download_banner.log manual_download_Procurement.log manual_upload.log"

LOGDATE=`date +%Y%m%d`

for file in $LOGFILES
do
    cp $file $file.$LOGDATE
done

## Remove log files older than 30 days

for file1 in ${LOGFILES}.*
do
  find $file1 -mtime +30 -exec rm -v \;
done
However, the 2nd part isn't recognizing the files with a date suffix, ie. manual_download_banner.log.20150114 and is instead picking up all the $LOGFILES.

I've tried many variations $LOGIFILES.* and its driving me mad !

Thanks in advance.
 
Old 01-14-2015, 10:39 AM   #2
J Martin Rushton
Member
 
Registered: Jan 2015
Location: England
Distribution: Mainly CentOS
Posts: 31

Rep: Reputation: Disabled
If LOGFILES contains "l1 l2 l3", then the first loop expands to:

for file in l1 l2 l3

which is what you expect. The second loop expands though to:

for file1 in l1 l2 l3.*

which is not what you want. Can you not combine the two halves:

for file in ${LOGFILES}
do
cp $file $file.$LOGDATE
find $file.* -mtime +30 -exec rm -v \;
done
 
1 members found this post helpful.
Old 01-14-2015, 10:52 AM   #3
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 49

Original Poster
Rep: Reputation: 0
ah yes, combing has sorted it.

I knew it would be something simple.

Many thanks
 
Old 01-15-2015, 08:45 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Might speed things up a bit using "mv" instead of cp. But that depends on whether you want the original file to remain or not. Most deal with that by having the service creating the log files start a new one.
 
Old 01-16-2015, 04:30 AM   #5
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 49

Original Poster
Rep: Reputation: 0
ah yes sorry, cp was just in the script for testing. mv is now in

Cheers
 
  


Reply


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] Why does this simple script is not working? ismaelvc Linux - Newbie 6 07-03-2012 09:28 AM
Script to delete logfiles older than 1 day madhumithamohan Linux - Newbie 12 07-06-2011 08:59 AM
simple perl script not working vinaytp Linux - Newbie 1 06-19-2009 02:13 AM
Simple firewall script not working for me Gates1026 Linux - Newbie 4 04-16-2004 10:40 PM
simple bash script not working. e1000 Programming 4 01-14-2004 01:09 AM


All times are GMT -5. The time now is 07:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration