What I'm trying to do is manually run logrotate when my disk is greater than 90% full. I'm trying to do this using df -P and awk. I can get it to display the percentage, if it's > 90, but I can't quite figure out how to get awk to run logrotate -f /etc/logrotate.d/ if it's > 90.
Here's what I have that works so far:
Printing the percentage if it's > 90: df -P /dev/sda2 | tail -1 | awk '$5 > 90 {print $5}'
Trying to run logrotate
df -P /dev/sda2 | tail -1 | awk '$5 > 90 {system(logrotate -vf /etc/logrotate.d) /dev/sda2}'
df -P /dev/sda2 | tail -1 | awk '$5 > 90 {logrotate -f}'
I'm new to all of this, so the exact command would be greatly appreciated. My intent is to put this into a shell script, or as the command portion of a daily cron job.
Thanks for the help. Patrick.