SOLVED Using scripts to find root's email address

Do you use your root account's email address for receiving custom script reporting?


  • Total voters
    2

Hazimil

Contributor
Joined
May 26, 2014
Messages
172
Hi All

Would appreciate some community feedback here. I have written (and shared) a few scripts for my FreeNAS server which the enduser needs to edit to update their email address, and I was looking at how I could remove this step, to make the scripts even easier to use.

I'm not sure about everyone else, but I send all reports (and script outputs) from my FreeNAS box to the email address used by root, and this email address is store in the file /etc/aliases. I have written the following snippet of code to extract the email address assigned to root:

Code:
grep -v '#' /etc/aliases | grep root: | cut -c 7-

Basically the code:
  1. strip all lines with a # (i.e. comments)
  2. looks for the line starting root:
  3. cut the first 6 characters from that line
  4. leaving an email address
I was wondering if anyone would be free to run this line of code on their box to confirm that it also correctly extracts their root's email address. Finally, I would appreciate an answer to the poll, to ascertain as to whether its worth my time doing this or not for my scripts.

Yours
Jonathan
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Why don't you just send the mail to "root" and let the configured alias do its magic? Hint: there can be more than one email address in any given alias ;)

HTH,
Patrick
 

Hazimil

Contributor
Joined
May 26, 2014
Messages
172
Why don't you just send the mail to "root" and let the configured alias do its magic? Hint: there can be more than one email address in any given alias

Ahh, thanks. Didn't know could just send to 'root', I'll have to test that - and didn't know there could be more than one alias!

J.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Every local user account is also a valid unqualified email address. And what did you think that aliases file was for? ;)

Patrick
 

Hazimil

Contributor
Joined
May 26, 2014
Messages
172
Well tested it and it worked sending an email to root. The more I do and learn, the more I find out I don't know!

Thanks for the feedback!

Jonathan
 
Top