Daily report on Freenas 9+

Status
Not open for further replies.

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
Hello,

I recently installed Freenas on my self-build system. All working properly, except that i'm missing daily/weekly reports. I've read that on earlier versions it was a build in feature, but the releasenote's of version 9.2.0 tell that you can add a cron job to do this.

http://www.freenas.org/whats-new/2013/12/freenas-9-2-0-release.html

I tried the following solution:

http://blog.frankvh.com/2014/03/15/freenas-weekly-status-email/

But it just reports back with the following e-mail messages (I do receive an e-mail :)! )

Subject:
Cron <root@freenas> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /bin/sh /mnt/Volume1/Software/Freenas/emailstatusreport.sh > /dev/null

Body/Message:
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: 9: Syntax error: word unexpected


Anyone that can help me to implement daily reports?
 
D

dlavigne

Guest
Do you get an error if you run /mnt/Volume1/Software/Freenas/emailstatusreport.sh from Shell?
 
D

dlavigne

Guest
sh /mnt/Volume1/Software/Freenas/emailstatusreport.sh

or

cd /mnt/Volume1/Software/Freenas
./emailstatusreport.sh
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
I get the following error:

[root@freenas ~]# sh /mnt/Volume1/Software/Freenas/emailstatusreport.sh
: not found1/Software/Freenas/emailstatusreport.sh:
: not found1/Software/Freenas/emailstatusreport.sh:
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: 9: Syntax error: word unexpected

Its the same error as in the e-mail.
 
D

dlavigne

Guest
Is the script set to executable? There is also a syntax error in line 9 of the script.
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
About line 9:

Changed:
) > /var/cover

in:
) >> /var/cover

Still the same error.

What do you mean by is the script set te executable (i'm a complete noob)? I made an .txt file, and changed the extension to .sh

I run the script by:
/bin/sh /mnt/Volume1/Software/Freenas/emailstatusreport.sh

Maybe the problem is bigger, i also tried to set SMART logs to be emailed every day, but they do not get emailed, only if the temperature reaches critical (if i set it at 25 C, the disks are 30/31C) i get an email.
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
Changed the script, i deleted the ) on line 9, and placed it at the end of the script. Now i get this email:

/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot create /var/cover: Permission denied
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh: cannot open /var/cover: No such file or directory
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
exit: Illegal number: 0
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
And if i changed the user to root:

/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
cannot open '
': invalid character '
' in pool name
cannot open '
': invalid character '
' in pool name
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
Traceback (most recent call last):
File "/etc/find_alias_for_smtplib.py", line 123, in <module>
main()
File "/etc/find_alias_for_smtplib.py", line 120, in main
do_sendmail(msg, to_addrs=to, parse_recipients=args.parse_recipients)
File "/etc/find_alias_for_smtplib.py", line 40, in do_sendmail
to_addrs = map(str.strip, em.get('To').split(','))
AttributeError: 'NoneType' object has no attribute 'split'
/mnt/Volume1/Software/Freenas/emailstatusreport.sh:
: not found
exit: Illegal number: 0

Now i'm really stuck. Isn't the script just crappy?
 

FreeNASBob

Patron
Joined
Aug 23, 2014
Messages
226
What do you mean by is the script set te executable (i'm a complete noob)? I made an .txt file, and changed the extension to .sh
The Unix-like operating systems will not just execute any old file the way Windows does. You have to explicitly mark the file as a file that is supposed to be executed. In the shell enter the following:

chmod u+x /mnt/Volume1/Software/Freenas/emailstatusreport.sh
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Well, the script you're using is pretty clearly borked, but the post at the link you gave seems pretty reasonable. I just tried it on my server (changing the email address and the pool name), and it worked without errors, though I'd need to edit it to cover all my drives. However, I noted that if I used copy/paste from Frank's page, each line had a lot of trailing spaces, which I could imagine causing problems depending on how you put it onto your server.

Try this: Copy his script (as in, highlight, Ctrl+C), from #!/bin/sh to exit 0. Then

# nano -w /mnt/Volume1/status.sh

Then paste it in, edit the email address and pool name, Ctrl+X, yes to save.

# chmod +x /mnt/Volume1/status.sh

The -w flag for nano causes it to not automatically wrap lines, which I suspect might be causing you problems. Then try to run it:

# /mnt/Volume1/status.sh

If it doesn't work, post the exact script you're using (masking the email address) using pastebin.com, and let's see what's happening. Mine is at http://pastebin.com/ryqheCD5 for comparison.
 
Last edited:

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
The nano command works, but as soon i try to paste, the whole shell disappears. I'm using the paste button on the lower-left.
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
When i try the chmod commands in Shell, I get an error: Operation not permitted
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
Probably, but i just got it working.

I copied your script and pasted in a .txt file which i renamed to status.sh. Then i tried to run the script by:

/bin/sh /mnt/share/something/somethingelse/emailstatusreport.sh

And it works. I get SMART data and all kind of stuff. So probably it was the unnecessary spaces in the file.

Can you tell me what /bin/sh stands for? If i removed it and started the command with /mnt i got an error in my email:
/mnt/Volume1/Software/Freenas/status.sh: not found

Another weird one:

Simultaneously with the e-mail from the script, i received a email containing:

/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found
/mnt/Volume1/Software/Freenas/status.sh:
: not found

So now i get two emails, one with the requested data, and this weird one. How is this possible?
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
The first line of the script, #!/bin/sh, identifies what command interpreter is used for the remainder of the script (in this case, /bin/sh, the standard shell--other options would include any of the shells, languages like python and perl, and no doubt others). With that line in place, you can directly execute it. Without that line in place, you need to specify the command interpreter, like so:

# /bin/sh /mnt/tank/status.sh

I'm not sure why you're getting two emails. Does that happen when you call it directly from the command line, or only from cron?
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
I only get it from Cron. From command line i get this:

[root@freenas ~]# /bin/sh /mnt/Volume1/Software/Freenas/status.sh
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:

And one correct e-mail log. So instead of receiving an additional email with above error, i now receive it in shell and Freenas sends a log to my email.
 

50Miles

Dabbler
Joined
Sep 16, 2014
Messages
18
I think it's something with spaces. If i delete all empty lines in the script, i only get the error one time like this:

[root@freenas ~]# /bin/sh /mnt/Volume1/Software/Freenas/status.sh
: not found1/Software/Freenas/status.sh:

instead of:

[root@freenas ~]# /bin/sh /mnt/Volume1/Software/Freenas/status.sh
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:
: not found1/Software/Freenas/status.sh:

But i cannot find anymore spaces or empty lines :(

EDIT: I still got one error line, but i think i'm not receiving the error message anymore. Will wait and see what happens.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Did you edit the file on a Windows PC? Text files in DOS use cr/lf as line terminators, while Unix uses only lf. I don't know if this would explain it--kind of grasping at straws at this point.
 

DJ9

Contributor
Joined
Sep 20, 2013
Messages
183
I had the same hunch as danb35. If you want / need to edit files on both a Unix type system and Windows, there is a small utility called dos2unix, or unix2dos. Saves you from manually doing all that editing.
 
Status
Not open for further replies.
Top