Bash script to check inodes and Email
Hello am trying to write a script that will check inodes of a folder then email me the details, this is what i have so far, though when i run it, it just shows nothing.
Code:
#!/bin/bash |
The inode usage is in percent, meaning a value between 0 and 100, and you're checking if it's greater than 200000. Of course it will never be true. Unless of course you really are expecting a value >200000%...the highest on any of my machines is 9%. If you post the output of "df -hi" it might clarify some things.
Also, you shouldn't put $dui in back ticks in your echo. Back ticks mean "execute what's inside here as if it were typed on the command line". $dui is just going to contain a number, which can't be executed as if it were a command, so it will fail. Remove the back ticks if you just want to echo the number. |
You haven't told it to send mail - you've simply defined a variable named MAILTO. You need to pipe your echo into a mail command like mailx.
You should use $() instead of backticks `. $() encapsulation is better because it allows nesting and also is less likely to be confused with single quotes. You don't need to reinvoke the command in your echo so `$dui`. You've already set the variable earlier so should just call it as $dui in your echo. (i.e. no backticks). Code:
#!/bin/bash |
Hey, thanks guys, i followed your advise and changed USAGE to 20% and also piped it to mailx, but it still doesn't send, i check my mail there is nothing, even in qmail queue there is nothing, is there something else am missing?
|
You shouldn't just write an entire script and hope that it works out of the box. BASH scripts are nice in that each line can be run by itself on the command line to see what it's doing.
What is the output of the following two commands on your box (just run them on the command line, not in a script). Code:
df -hi Code:
df -hi | sed -n '2p' | awk '{print $5}' | grep -v U | cut -d% -f1 |
This is the result.
~# df -hi Quote:
Quote:
|
Your inode usage is only 3%, which is why it's not sending any mail. The way the script is written, the inode usage needs to exceed USAGE in order for anything to be sent.
You could arbitrarily lower USAGE to 2 to test the script. |
Man thanks alot...
|
So how do i get the inode of a directory, say /var/www/vhosts/ and do a loop that will print each domain name that has exceeded 2%
|
inode percentage is a a percentage of filesystem NOT directory. Although you mount filesystems on directories called mount points it does not mean all directories are mount points.
To really figure out percentage for subdirectories or files inside a mount point you'd have to figure out: 1) How many inodes a specific filesystem allows. 2) How many inodes a given subdirectory or file uses. 3) Do a calculation to determine the percentage 2 is of 1. |
Thanks guys alot...
|
All times are GMT -5. The time now is 09:53 PM. |