ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
It worked! It does raise another question for me, though.
I tried the same script on two machines. Machine 1 had files Afile.1 through .4, and Bfile.1 through .4, and Cfile.1 through .4. Machine 2 had only Afile.1 through .4. All of the files on Machine 1 were concatenated, just as I wanted. And, on Machine 2, Afile.1 through .4 were concatenated. But, files named Bfile.? and Cfile.? were created in the directory. Of course, I don't want that to happen.
So, in order to use the same script on different machines where any combination of Afiles, Bfiles, and Cfiles might exist, what should I do so that "missing" files are ignored. Hopefully, with modifications, your construct can be made to do that. BTW, the use of Afile, Bfile, and Cfile are purely illustrative. They could be named Curly.1, Moe.1, and Larry.1, etc.
It worked! It does raise another question for me, though.
I tried the same script on two machines. Machine 1 had files Afile.1 through .4, and Bfile.1 through .4, and Cfile.1 through .4. Machine 2 had only Afile.1 through .4. All of the files on Machine 1 were concatenated, just as I wanted. And, on Machine 2, Afile.1 through .4 were concatenated. But, files named Bfile.? and Cfile.? were created in the directory. Of course, I don't want that to happen.
So, in order to use the same script on different machines where any combination of Afiles, Bfiles, and Cfiles might exist, what should I do so that "missing" files are ignored. Hopefully, with modifications, your construct can be made to do that. BTW, the use of Afile, Bfile, and Cfile are purely illustrative. They could be named Curly.1, Moe.1, and Larry.1, etc.
As ever, thanks.
Diggy
To ignore "missing" files, you can do existence check like this:
In colucix's script, instead of
Code:
for file in /var/log/fileA.? /var/log/fileB.? /var/log/fileC.?
do
> $file
done
Try:
Code:
for file in /var/log/fileA.? /var/log/fileB.? /var/log/fileC.?
do
if [ -f $file ]; then
> $file
fi
done
If services log to file then logrotate is the answer (and not script) if you want to retain logging. If you do not want to retain logging then do not log (as much as you do now).
If services log to file then logrotate is the answer (and not script) if you want to retain logging. If you do not want to retain logging then do not log (as much as you do now).
Good point, unSpawn! I was too focused on the shell issues to think about the logical thing to do.
UnSpawn of rkhunter fame? Excellent. I use that great program!
You're right about logrotate, but I need to use the script, regardless. Let me elucidate (finally got to use that word :-) ).
The box I'm running the script on is old - old OS, old hardware, small disk. Because so much log activity takes place, the /var directory fills up about every four weeks because of the growth of certain log files. Logrotate rotates them fine, but can't keep up with the growth. I suppose I could change the rotation to a shorter period, or do it based on file size, but I'll be doing a hardware refresh to a bigger, better box in about eight weeks, so the script will be a stopgap measure. And, I'm not concerned about deleting precious log files; they're parsed on a continuous basis for events of interest. Finally, rather than giving this man a fish, you've helped teach him how to fish, thereby feeding him for live.
As an aside, the box that this script will be running on has provided great service to us for nearly seven years. As mentioned, it'll be peacefully retired in about two months. I've tried to take all of the necessary precautions in case it fails but, God willing, it'll make it to the finish line.
The last construct you showed me is interesting, and well beyond my scripting level. I'll study it, and test it on a throw-away VM to see how it performs.
the box that this script will be running on has provided great service to us for nearly seven years. As mentioned, it'll be peacefully retired in about two months. I've tried to take all of the necessary precautions in case it fails but, God willing, it'll make it to the finish line.
A proper burial would be a bit over the top but I hope you give its remnants a good final destination?..
Quote:
Originally Posted by Diggy
The last construct you showed me is interesting, and well beyond my scripting level. I'll study it, and test it on a throw-away VM to see how it performs.
It's simple: run lsof and only show items in /var/log | awk for any line that has "log/" in it and print the last field (file name) | sort output showing unique items only | while read the output line by line into the variable "LOG"; and for each item do
[ `stat the item only returning its size in bytes` and check if the size is greater than $[10240*50] ] if it is then empty the item
done.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.