need a shell scrit urgent description in message
HI Everyone, need a shell script which checks size of a directory and if it gets greater than 1 GB then delete all the files in it.
ex: dir : /var/log/ /log contains numerous .log files, so script should delete .log files always when /log size is greater than 1 GB , it should not delete the directory |
Quote:
Read the "Question Guidelines" link in my posting signature. We will be happy to HELP you with things, but asking for a handout and showing ZERO effort of your own, isn't the way to get help. There are MANY THOUSANDS of bash scripting guides you can easily find with a Google search...just like you found THIS site. |
Quote:
You need them when problems happen so that you can find out what the problem is, and find out how to fix it. If all you are concerned about is the old logs, you might look into using an existing script - "logrotate". It is also frequently installed as part of installation. From the manpage: Code:
LOGROTATE(8) System Administrator's Manual LOGROTATE(8) |
In the interest of actually helping a newbie
you could use the find command to find files older than X days and delete them something like Code:
find /var/log/ -maxdepth 1 -type f -mtime +30 -name Code:
find /var/log/ -maxdepth 1 -size 5M -name "*.log*" to delete, just add "- delete" to the end of the command. and if you like it, add it to your root's cronjobs Code:
EDITOR=nano sudo crontab -e |
Quote:
I'm very hesitant to help ANYONE who doesn't show any effort of their own, especially with a topic like this, that has so much information, examples, and tips available with a very quick Google search. |
i mostly concur... but sometimes people just don't even know how to start, not even what to google. i work at a university and you would think the employees are the brightest people around, but they are VERY FAR FROM IT (self inclusive).
|
Quote:
Quote:
In this case, it's a systems administrator who needs a script to perform maintenance...which would be like a neurosurgeon, asking how to perform surgery. |
Quote:
|
Quote:
Want a better one? How about "delivery driver not knowing how to start their car"? |
yeah... that one is better.
:) |
All times are GMT -5. The time now is 12:01 PM. |