DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I created a script to generate a report (Eximstats Report).
It ran successfully the first time I executed it.
However for 2 times after that it has not been running properly.
Actually the beginning part of the script copies mainlog files within a date range into another directory. This does not work properly anymore. Meaning the mainlog file that is copied over to the destination directory is 0 in size, and not the actual size in /var/log/exim4.
Please help correct the find statement for this function :
I don't know the version history of find but ! or \! is the same as -not.
The command should find all the files that match "mainlog*" between the desired dates. The the basic find command works for me but I changed the dates to match my system. Did you run the script "for 2 times after" consecutively i.e. within a short time period?
The log files do rotate but if the script is run within a short period of time I would expect them to be copied to the destination directory to be the same size.
The first time I ran the script was on 6/9/2017 and the second time was on 8/9/2017.
Also,if I execute ONLY the find command above in the terminal it works, but if it is used in a full script, it
does not run as needed. It does not copy all the mainlog files with the required size.
The mainlog files rotate daily. Therefore it is not possible for the files to be in same size if I copy it over
on two different dates.
See the suggestion about "set -x" mentioned in #2 above to see what you are actually running. If you are running this as a cron job then the output will be catured automatically and sent as a mail.
I have included "set -xv" at the beginning of the script as suggested.
When I execute the script now, I can see the verbose output, however, there seems to be no error given for the find command :
Code:
dest=(/var/log/exim4/"$YEAR"/"$DIR2"/)
+ dest=(/var/log/exim4/"$YEAR"/"$DIR2"/)
mkdir -p /var/log/exim4/$YEAR/$DIR2
+ mkdir -p /var/log/exim4/2017/Sep2017_Blast_BC07
find /var/log/exim4 -maxdepth 1 -type f -name 'mainlog*' -newermt $EIGHTH ! -newermt $TOMORROW -exec cp {} $dest \;
+ find /var/log/exim4 -maxdepth 1 -type f -name 'mainlog*' -newermt 2017-09-08 '!' -newermt 2017-09-13 -exec cp '{}' /var/log/exim4/2017/Sep2017_Blast_BC07/ ';'
cd $dest
+ cd /var/log/exim4/2017/Sep2017_Blast_BC07/
for x in ./mainlog*
do
t=$(echo $x | sed 's/\.gz$/.filtered/');
exigrep L28stream1 $x | egrep -v "jiun.shyong.hor@ericsson.com|chander.c.shekher@ericsson.com|nagios|L28eagle" > $t
done
This works like a gem! It copies over the files exactly with the correct size.
But when I put this chunk in the whole script, then the problem begins again.
Means another section of the script, below this code is causing the problem?
Why do you say set -xv was not in effect when we can see the complete verbose output of what the command does, etc?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.