Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
Code:
[root@storage01 ~]# ls -al /mnt/tank/media/Library/Scripts/FreeNAS
total 90
drwxrwxr-x+ 2 root    media    10 May 31 17:33 .
drwxrwxr-x+ 3 media  media     3 May 20 12:31 ..
-rwxrwxrwx  1 root    wheel   1369 May 20 13:42 config_backup_to_email.sh
-rwxrwxrwx  1 root    wheel    568 May 20 13:38 display_cpu_hdd_temp.sh
-rwxrwxrwx  1 root    wheel    636 May 20 13:40 display_hdd_info.sh
-rwxrwxrwx  1 root    wheel   2106 May 31 17:33 fan_control.sh
-rwxrwxrwx  1 root    wheel   4271 May 20 11:36 sata_smart_report.sh
-rwxrwxrwx  1 root    wheel   4411 May 20 18:25 spincheck.sh
-rwxrwxrwx  1 root    wheel    831 May 20 13:35 ups_report.sh
-rwxrwxrwx  1 root    wheel   3997 May 20 12:38 zpool_report.sh
[root@storage01 ~]# echo $SHELL
/bin/csh
[root@storage01 ~]#


CeZNY7i.png

7Rn4DmU.png
 
Last edited:

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i just checked my cron jobs and i have - redirect stdout enabled on all my tasks - try that !
 

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11

ethereal

Guru
Joined
Sep 10, 2012
Messages
762

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
are you getting any cron errors ?
 

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
strange thing is that the scripts don't even show up in the cron log, except one.
Code:
[root@storage01 /var/log]# tail -f cron
Jun  1 08:10:00 storage01 /usr/sbin/cron[59565]: (root) CMD (/usr/libexec/atrun > /dev/null 2>&1)
Jun  1 08:11:00 storage01 /usr/sbin/cron[59674]: (operator) CMD (/usr/libexec/save-entropy > /dev/null 2>&1)
Jun  1 08:15:00 storage01 /usr/sbin/cron[59874]: (root) CMD (PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /mnt/tank/media/Library/Scripts/FreeNAS/fan_control.sh > /dev/null)
Jun  1 08:15:00 storage01 /usr/sbin/cron[59877]: (root) CMD (/usr/libexec/atrun > /dev/null 2>&1)
Jun  1 08:20:00 storage01 /usr/sbin/cron[60178]: (root) CMD (PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /mnt/tank/media/Library/Scripts/FreeNAS/fan_control.sh > /dev/null)
Jun  1 08:20:00 storage01 /usr/sbin/cron[60180]: (root) CMD ([ -s /tmp/mail.queue ] && /usr/local/bin/python /usr/local/www/freenasUI/tools/mailqueue.py)
Jun  1 08:20:00 storage01 /usr/sbin/cron[60181]: (root) CMD (/usr/libexec/atrun > /dev/null 2>&1)
Jun  1 08:22:00 storage01 /usr/sbin/cron[60350]: (operator) CMD (/usr/libexec/save-entropy > /dev/null 2>&1)
Jun  1 08:25:00 storage01 /usr/sbin/cron[60491]: (root) CMD (PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /mnt/tank/media/Library/Scripts/FreeNAS/fan_control.sh > /dev/null)
Jun  1 08:25:00 storage01 /usr/sbin/cron[60493]: (root) CMD (/usr/libexec/atrun > /dev/null 2>&1)
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
did you see this post?

The root shell doesn't matter because there's a shebang in the script ;)

I'm afraid it doesn't work either with the "Redirect Stdout" checkbox enabled.
Here's the contents of the sata_smart_report.sh and its output after running the script manually, few moments ago.

https://gist.github.com/sv2241/ab7a081e8460f58086f60f4d66a170d9
https://gist.github.com/sv2241/b5256bd4784a63e036ed343257972aef

If relevant, please note that I'm running on latest 9.10 version - FreeNAS-9.10-STABLE-201605240427 (64fcd8e)

Everything looks good.
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
if it was me i'd try a new simple script emailing you something like - hello

then try a new cron job and see if that one works.
 

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
Thanks for the suggestion, ethereal.
test.sh was added in cron to run every 5 minutes and by user root. Its contents is shown below:

Code:
[root@storage01 ~]# cat /mnt/tank/media/Library/Scripts/FreeNAS/test.sh
#!/bin/sh
echo "Bla bla bla" | sendmail ***redacted***@gmail.com
[root@storage01 ~]# /mnt/tank/media/Library/Scripts/FreeNAS/test.sh
[root@storage01 ~]#


Same as before, whenever the script is run from OS-level, I get an e-mail. When added in cron through FreeNAS UI, nothing happens.
 
Last edited:

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
did you - chmod +x

i don't know if the scripts will run manually without it. so it maybe a stupid question but it is all that i can think of.
 

Linkman

Patron
Joined
Feb 19, 2015
Messages
219
The cron environment isn't the same as your login or shell environment, perhaps there is a environment variable value missing from the cron executions?
 

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
Although the execute bit was already set to all script files (777), when trying to set the +x flag again I got an "Operation not permitted" error. All datasets were configured with UNIX permissions, now I see the main one (which hold these scripts as well) is Windows ACL. How is this possible considering I'm the only person with access to this box and I have NOT changed it?
L.E.: I will open a separate thread for the above as this is off-topic.

Hope this helps

Code:
[root@storage01 /mnt/tank/media/Library/Scripts/FreeNAS]# env
REMOTEHOST=10.1.10.10
HOST=storage01.LOCAL
SHELL=/bin/csh
TERM=xterm
SSH_CLIENT=10.1.10.10 65319 22
SSH_TTY=/dev/pts/0
GROUP=wheel
USER=root
HOSTTYPE=FreeBSD
PAGER=less
LSCOLORS=ExGxFxdxCxegedabagExEx
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin:/usr/local/fusion-io
MAIL=/var/mail/root
BLOCKSIZE=K
PWD=/mnt/tank/media/Library/Scripts/FreeNAS
EDITOR=vi
SHLVL=2
HOME=/root
OSTYPE=FreeBSD
VENDOR=amd
MACHTYPE=x86_64
LOGNAME=root
SSH_CONNECTION=10.1.10.10 65319 10.1.10.50 22
_=/usr/bin/env
OLDPWD=/mnt/tank/media/Library/
[root@storage01 /mnt/tank/media/Library/Scripts/FreeNAS]# ls -al
total 100
drwxrwxr-x+ 2 root    media    12 Jun  1 16:40 .
drwxrwxr-x+ 3 media  media     3 May 20 12:31 ..
-rwxrwxrwx  1 root    wheel   1369 May 20 13:42 config_backup_to_email.sh
-rwxrwxrwx  1 root    wheel    568 May 20 13:38 display_cpu_hdd_temp.sh
-rwxrwxrwx  1 root    wheel    636 May 20 13:40 display_hdd_info.sh
-rwxrwxrwx  1 root    wheel   2106 May 31 17:33 fan_control.sh
-rwxrwxrwx  1 root    wheel   4271 May 20 11:36 sata_smart_report.sh
-rwxrwxrwx  1 root    wheel   4411 May 20 18:25 spincheck.sh
-rwxrwxr-x+ 1 root    wheel     66 Jun  1 15:43 test.sh
-rwxrwxr-x+ 1 root    wheel    424 Jun  1 14:55 test01.sh
-rwxrwxrwx  1 root    wheel    831 May 20 13:35 ups_report.sh
-rwxrwxrwx  1 root    wheel   3997 May 20 12:38 zpool_report.sh
[root@storage01 /mnt/tank/media/Library/Scripts/FreeNAS]# chmod +x ups_report.sh
[root@storage01 /mnt/tank/media/Library/Scripts/FreeNAS]# chmod +x test.sh
chmod: test.sh: Operation not permitted
[root@storage01 /mnt/tank/media/Library/Scripts/FreeNAS]#
 
Last edited:

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
if you change the permissions to unix does that solve your problem ?
 

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
Copied one of the scripts to /root/ , set the execute bit and changed the path in cron accordingly. Same results
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, you definitely have a haunted system... :confused:
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194

sv2241

Dabbler
Joined
Apr 14, 2016
Messages
11
Well, what do you know? After a restart, the emails started flooding my Inbox. Don't ask me what was wrong, it's still a mystery. Thank you for your patience and eagerness to help
 

Dice

Wizard
Joined
Dec 11, 2015
Messages
1,410
Heya,
I'd just gave the 'email config' script a try.
Got my mail address changed and working.
I receive the following:
Code:
Automatic backup of FreeNAS config failed.

The config file is corrupted!

You should correct this problem as soon as possible.

...?

Exporting/saving config from the GUI works fine.
Verify Install also completes successfully.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Which version of FreeNAS? those scripts are only tested on 9.3, not 9.10.
 
Top