/Var

Hi,
Please suggest me how to clear the /Var if it exceeds threshold limit, and what factors need to be considered while clearing it.

Thanks!!

By the the /Var I am assuming you mean the /var directory tree.

/var/log is where syslogd writes important logfiles. You can remove older files from there if you have a problem.

/var/tmp can also be cleaned up.
This sample cleans up only if the 2GB limit has been reached. Use GB in your limit if you want to use this code.
It removes old syslog files and cleans up /var/tmp (I guessed where /var/tmp might be, some systems do not even have one, and the directory can be /var/admin/tmp or some such).

Be careful with this script you could do damage to the system by wholesale removal of any old big file in /var. Also consider increasing the size of the /var/ filesystem, there usually is one.

#!/bin/ksh
limit=2   # 2 GB limit
now=$(du -hs /var | grep GB  sed 's/GB//')
[ -z "$now" ] && exit   # early exit
[ $now -le $limit ] && exit   # less than limit
find /var/log -name 'syslog.*' -mtime +30 -exec rm {} \;  # remove 30+ day old syslog
[ -d /var/tmp ] &&  find /var/tmp  ! -user root -mtime +5 -type f -exec rm {} \;
exit
1 Like

The above method provides a perfect method of removing files under /var. You can always use the method that Jim has told, but you need to extra careful while giving those commands as Jim has mentioned...
Just to be sure, in place of "-exec rm {} " give "-exec ls -l {}" to see what are the files that you are about to remove.

And if you need assistance in tracking what type of files to be removed/nullified, then this link I think might be somewhat useful for you.

http://www.unix.com/solaris/25840-filesystem-full-what-look.html

1 Like