LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-11-2021, 06:23 AM   #1
karan2119
LQ Newbie
 
Registered: Feb 2021
Posts: 1

Rep: Reputation: Disabled
I am trying to make a script to first check and empty those file in /var/log/ which are greater than 500MB


#!/bin/bash
log_dir=`ls -laSh /var/log/`

for entry in $log_dir
do
Max=$(`stat -f %s "$log_dir"`)
if [[ "$Max" -ge 5000000000 ]]
then
echo "file is over $entry"
#echo /dev/null > $log_dir
else
echo "$entry, File is fine "$Max""
fi
done
 
Old 02-11-2021, 07:37 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,764

Rep: Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764
I have solved that problem, but there are a dozen tricks and traps to consider. I stopped doign that manually with ascript when logrotate got good over 20 years ago. Use and properly configure logrotate to do the log rotation/removal. Using the right tool is far safer than trying to reinvent the horse.
 
1 members found this post helpful.
Old 02-11-2021, 04:48 PM   #3
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
I agree with wpeckham. Logrotate can be configured by size, time, or other and it is easy enough to do that a simple configuration can handle what you want. look at the logrotate man page and at the files in /etc/logrotate.d The size option is what you are interested in.
 
1 members found this post helpful.
  


Reply



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
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
[SOLVED] iptables troubleshooting icmp and best place to log /var/log/messages or /var/log/iptables JockVSJock Linux - Security 18 02-12-2016 12:31 AM
LXer: With greater permissions, comes greater responsibility LXer Syndicated Linux News 0 02-20-2014 03:11 PM
[SOLVED] /var/log/boot.log is empty in RHEL5.5. How to enable the boot log? rajivdp Linux - Newbie 1 08-12-2010 08:11 AM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM

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

All times are GMT -5. The time now is 12:28 PM.

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