Using check_space.py

Status
Not open for further replies.

andyl

Explorer
Joined
Apr 20, 2012
Messages
76
Hi,

I'm trying to use check_space.py to notify me when available space on my FreeNAS box drops below 25Gb.

I ran it once with the following options;
Code:
python /usr/local/www/freenasUI/tools/check_space.py -d [dataset] -t 10%


I do have less than 10% disk free, and I duly received an email confirming that, so I know the script & email work. But if have a 5Tb volume, that spends most of its time with less than 10% available. I want to be informed if it drops below 25Gb. So I ran the command as follows;
Code:
python /usr/local/www/freenasUI/tools/check_space.py -d [dataset] -t 25G


But this time I received no email. I can find no documentation on the script, and I don't know enough Python to figger it out myself.

Is there a time delay on the script, or am I using it wrong?

Endgame is to have it running from a timed job, as detailed in the following thread;
http://forums.freenas.org/index.php...e-space-dips-below-a-defined-threshold.15892/
I'm more familiar with Linux than BSD, and I'd normally run it from cron.daily - is there a similar mechanism on FreeNAS?

Thanks
 

Yatti420

Wizard
Joined
Aug 12, 2012
Messages
1,437
Works for me.. Can you verify permissions etc.. Most likely didn't run on the second pass.. I never touch these files with Windows or they always break..
 

andyl

Explorer
Joined
Apr 20, 2012
Messages
76
I am running whilst SSHed in as root on the FreeNAS box - I don't think its a Windows or permissions issue.
The script doesn't issue any errors - just runs and drops back to a command prompt, with the command as above.
I have run it multiple times, and get the same result every time (after the first).

How often do you run the script?

Thanks,
Andy.
 

Yatti420

Wizard
Joined
Aug 12, 2012
Messages
1,437
Use cron to execute the script whenever you want.. See the link in your original post..
 

andyl

Explorer
Joined
Apr 20, 2012
Messages
76
But if it doesn't work when issued as a command, why would it work from cron?

I set it up on a 5 min cycle anyways, so root's crontab looks like this;
Code:
*/5 * * * *  [path]/check_space.sh


Initially the check_space.sh script looked like;
Code:
#!/bin/sh
for pool in `zpool list -Ho name`
do
  python /usr/local/www/freenasUI/tools/check_space.py -d $pool -t 10%
done


But I started getting emails indicating that the script was falling to find zpool;
Code:
[path]/check_space.sh: zpool: not found


So I changed the check_space script to;
Code:
python /usr/local/www/freenasUI/tools/check_space.py -d [pool-name] -t 10%


Now I'm getting errors from cron indicating that it can't find python.
Do I need to export the path to cron in some fashion?

Thanks,
Andy.
 

croca

Cadet
Joined
Jul 5, 2012
Messages
6
But if it doesn't work when issued as a command, why would it work from cron?

I set it up on a 5 min cycle anyways, so root's crontab looks like this;
Code:
*/5 * * * *  [path]/check_space.sh


Initially the check_space.sh script looked like;
Code:
#!/bin/sh
for pool in `zpool list -Ho name`
do
  python /usr/local/www/freenasUI/tools/check_space.py -d $pool -t 10%
done


But I started getting emails indicating that the script was falling to find zpool;
Code:
[path]/check_space.sh: zpool: not found


So I changed the check_space script to;
Code:
python /usr/local/www/freenasUI/tools/check_space.py -d [pool-name] -t 10%


Now I'm getting errors from cron indicating that it can't find python.
Do I need to export the path to cron in some fashion?

Thanks,
Andy.

Yes, you need to specify the python path in the script:
/usr/local/bin/python /usr/local/www/freenasUI/tools/check_space.py -d [pool-name] -t 10%

For example:

#!/bin/sh
PYTHON=`which python`
THRESHOLD="10%"
for POOL in `zpool list -Ho name`
do
$PYTHON /usr/local/www/freenasUI/tools/check_space.py -d $POOL -t $THRESHOLD
done
 
Status
Not open for further replies.
Top