Very weird, I can't figure out why it's not matching up the if's and fi's. Honestly, I don't know a whole lot about shell scripting and it's possible I messed something up, but I can't figure out what it might be. If you want to hop on IRC, I can help you troubleshoot it on there.
I ran my whole script through there and I'm working on correcting stuff, but it didn't come up with anything major.Paste your scripts into http://www.shellcheck.net. It's a fantastic 'lint' analyzer for shell scripts that I've found invaluable.
Updated the script: https://github.com/edgarsuit/FreeNAS-Report
Changes:
TODO:
- Config backup now attached to report email
- Added option to turn off config backup
- Added option to save backup configs in a specified directory
- Power-on hours in SMART summary table now listed as YY-MM-DD-HH
- Changed filename of config backup to exclude timestamp (just uses datestamp now)
- Config backup and checksum files now zipped (was just .tar before; now .tar.gz)
- Fixed degrees symbol in SMART table (rendered weird for a lot of people); replaced with a *
- Added switch to enable or disable SSDs in SMART table (SSD reporting still needs work)
- Added most recent Extended & Short SMART tests in drive details section (only listed one before, whichever was more recent)
- Reformatted user-definable parameters section
- Added more general comments to code
- Improve SSD reporting, going to have to add them in a new table
- Run through shellcheck for general improvements
- Add support for conveyance SMART tests
awk: syntax error at source line 19 context is switch (powerTimeFormat) >>> { <<< awk: illegal statement at source line 20 awk: break illegal outside of loops at source line 23
Hello,Thanks guys, I've been learning a lot running through these scripts and have just about everything working the way I want.
The current version of melp's script I'm getting some errors when I run it in the shell:
Code:awk: syntax error at source line 19 context is switch (powerTimeFormat) >>> { <<< awk: illegal statement at source line 20 awk: break illegal outside of loops at source line 23
and repeated 6 times (I'm assuming for each of my 6 drives)
The formatted SMART report summary is empty in the emailed output file (but the detail text output is there). Tried a couple different copy/paste (using notepad++) and the script works for the most part, but I can't find where it looks like any syntax errors.
-SJ
Thanks a lot for your workI'm guessing that your version of awk doesn't seem to like switch statements. I'll update the script to use if/elseif statements instead.
I'm guessing that your version of awk doesn't seem to like switch statements. I'll update the script to use if/elseif statements instead.
I am on the latest release, so I don't think this will be the reasonInteresting, had never even heard of awk before now (had to do some quick wikipedia reading :) )
Would it have to do with the FreeNAS version? currently running 9.10.2-U4. Though something as basic as a switch statement you would think wouldn't be a problem.
Sweet. I'll give it a go tonight. Btw, do you have the ability to load the versions on github? I didn't keep rv01 which worked well and couldn't revert when rv02 failed to run. Looking forward to running rv03!Regardless, I switched it to use if/else statements instead. Updates are on github (including a new flag to change the format of the Power On Hours column based on the comment from Ruff-Hi.
https://github.com/edgarsuit/FreeNAS-Report
if ([ "$includeSSD" == "true" ]); then #71 drives=$(for drive in $(sysctl -n kern.disks); do \ if ([ "$(smartctl -i /dev/"${drive}" | grep "SMART support is: Enabled")" ]); then printf "%s " "${drive}"; fi #75 done | awk '{for (i=NF; i!=0 ; i--) print $i }')
FreeNASReport.sh: 75: Syntax error: "done" unexpected (expecting "then") FreeNASReport.sh: 71: Syntax error: Error in command substitution
if ([ "$(smartctl -i /dev/"${drive}" | grep "SMART support is: Enabled")" ]); then ..... ^-- SC2143: Use grep -q instead of comparing output with [ -n .. ].
if smartctl -i /dev/"${drive}" | grep -q "SMART support is: Enabled"; then
for the if statement line, but similar syntax doesn't work for the section below it because of the pipe). If you move the "then" on line 72 to a new line, does that resolve it? That "then" is what it's looking and not finding for some dumb reason.I got it to pass that section withStill no idea what's going on with it.
drives="da0 da1 da2 da3"; if smartctl -i /dev/"${drive}" | grep -q "SMART support is: Enabled" then printf "%s " "${drive}"; fi awk '{for (i=NF; i!=0 ; i--) print $i }'
poolNum=0 for pool in $pools; do # zpool health summary
drives="da0 da1 da2 da3";
isn't doing anything any more. The then
on the same line of the if
shouldn't cause issues, so I don't know what the fuck. I'm thinking maybe it was the / after the do? pools=$(zpool list -H -o name)
line at the bottom of that first section as well. Try the following code for the ###### Auto-generated Parameters
section. If it works, I'll update the git repo so you can use the main branch again:###### Auto-generated Parameters host=$(hostname -s) logfile="/tmp/smart_report.tmp" subject="Status Report and Configuration Backup for ${host}" boundary="gc0p4Jq0M2Yt08jU534c0p" if [ "$includeSSD" == "true" ]; then drives=$(for drive in $(sysctl -n kern.disks); do if [ "$(smartctl -i /dev/"${drive}" | grep "SMART support is: Enabled")" ]; then printf "%s " "${drive}" fi done | awk '{for (i=NF; i!=0 ; i--) print $i }') else drives=$(for drive in $(sysctl -n kern.disks); do if [ "$(smartctl -i /dev/"${drive}" | grep "SMART support is: Enabled")" ] && ! [ "$(smartctl -i /dev/"${drive}" | grep "Solid State Device")" ]; then printf "%s " "${drive}" fi done | awk '{for (i=NF; i!=0 ; i--) print $i }') fi pools=$(zpool list -H -o name)
Okay everybody. Sometimes you just have to stand up and admit your mistakes. I've had all these issues because I was editing the script in Notepad++ and then copying it to FN. That didn't work, something was screwing up between dos and unix. I've since directly copied the report.sh to FN and edited in nano and all is well, the script works perfectly fine. I'm sorry...
Regardless, I switched it to use if/else statements instead. Updates are on github (including a new flag to change the format of the Power On Hours column based on the comment from Ruff-Hi.