LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-16-2015, 12:28 AM   #1
DebraBergeson
LQ Newbie
 
Registered: Nov 2015
Posts: 1

Rep: Reputation: Disabled
${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 11-16-2015, 12:53 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
And why would it? Think of what it would look like after the expansion:
Code:
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.*  <== here is your asterisk
 
Old 11-16-2015, 12:58 AM   #3
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Rep: Reputation: 39
Yes, so you are only adding the .* to the last argument in that var, like grail said.

Also, you find command is not right. You need to use the -name switch. like so:

Code:
find . -name $file1 -mtime +30 -exec rm -v \;
So what you really want to do is this if you want to only target files with a dot and anything after the file name.

Code:
## Remove log files older than 30 days
for file1 in ${LOGFILES}
do
  find . -name "${file1}.*" -mtime +30 -exec rm -v \;
done
Or if you want to include all files in the search and remove:

Code:
## Remove log files older than 30 days
find . -mtime +30 -exec rm -v \;
 
Old 11-16-2015, 06:39 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275
you can easily check what does ${LOGFILES}.* really mean (how it will be evaluated by the shell) by executing:
echo ${LOGFILES}.*
 
  


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
Simple script question: ${LOGFILES}.* not working SmurfGGM Linux - Newbie 4 01-16-2015 03:30 AM
RHEL 5.* logfiles MeeLee Linux - Newbie 3 08-25-2009 09:15 AM
mysql logfiles cccc Debian 1 02-24-2009 08:00 AM
how to monitor logfiles ganninu Linux - General 4 12-07-2003 06:36 AM
Logfiles wonderpun Linux - General 3 09-01-2002 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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