Ah, I figured it out. I needed:
So now on to another question. Could the above code been written better? Is anything in it excessive?Code:declare -i block_usage
Ok, to start with I’m not much of a programmer, so bare with me if this script is a bit sloppy and longer than it need be. The script is supposed to check a users quota usage on given partitions and then send a warning email if they are nearing their limit.
However, when I test the script, i get the following error
I’m pretty sure the error is with the if/then comparison [ "$quota_usage" -gt $QUOTA_LIMIT ], but what’s wrong, I don’t know. Could it be that $quota_usage is a string and not an integer? If so, is it possible to cast $quota_usage as an integer, or is this asking too much of bash? I’m sure I’m overlooking something very simple, but like I said, I’m not much of a coder.Code:[ : : integer expression expected
Here’s the full script
Code:#!/bin/bash QUOTA_LIMIT=8960 MAIL_BODY="/etc/QuotaMail.txt" MAIL_DIR="/var/spool/mail/" WARNING_SUBJECT="WARNING: YOUR MAIL ACCOUNT IS REACHING ITS QUOTA LIMIT" PARTITIONS="/dev/ida/c0d0p5 /dev/ida/c0d0p6" awk -F: '{ print $1 }' /etc/passwd > /tmp/usernames { while read username; do for i in $PARTITIONS; do block_usage=`quota $username | grep $i | awk -F' ' '{ print $2 }' | sed s/*//` if [ $block_usage -gt $QUOTA_LIMIT ]; then has_exceeded_quota_limit="yes" else has_exceeded_quota_limit="no" fi done if ! grep "$WARNING_SUBJECT" "$MAIL_DIR"$username && [ "$has_exceeded_quota_limit" = "yes" ]; then cat $MAIL_BODY | mail -s "$WARNING_SUBJECT" $username fi done } < /tmp/usernames && rm /tmp/usernames
Ah, I figured it out. I needed:
So now on to another question. Could the above code been written better? Is anything in it excessive?Code:declare -i block_usage
Why not just use quotacheck ??
You set everything in /etc/warnquota.conf, and have your /etc/cron.daily/warnquota
It handles everything for you, and its just a part of your normal quota package.. No need to make a manual scan of the file structure..:~# cat /etc/cron.daily/warnquota
#!/bin/sh
/usr/sbin/warnquota
(That is, if you are using quotas for the users)
See, I knew there was an easier way to do this. warnquota is on my system, but not warnquota.conf. Does anyone have any suggestions as to what its syntax should be?Why not just use quotacheck ??
You set everything in /etc/warnquota.conf, and have your /etc/cron.daily/warnquota
It handles everything for you, and its just a part of your normal quota package.. No need to make a manual scan of the file structure..
(That is, if you are using quotas for the users)
To make this quick… And easy(tm)Does anyone have any suggest as to what it’s syntax should be?
Code:redhead@odin:~# rpm -q quota quota-3.01pre9-3 redhead@odin:~# cat /etc/warnquota.conf # this is an example warnquota.conf # ; ; and # type comments are allowed # and even blank lines MAIL_CMD = "/usr/sbin/sendmail -t" FROM = "root@localhost" SUBJECT = Disk Quota usage on system CC_TO = "[email protected]" SUPPORT = "[email protected]" PHONE = "" # # end of example warnquota.conf file # redhead@odin:~# su -c "cat /etc/quota.conf " Password: redhead@odin:~#
Bookmarks