Piping shell script stdout to the nightly e-mail logs

Status
Not open for further replies.

gsk3

Cadet
Joined
Sep 12, 2017
Messages
5
I just wrote a shell script to use rclone to backup my files (script below in case someone finds it useful; nothing fancy there).

I'd like to have its output piped into the log file that's e-mailed out every day (the one that you get when you set up your email in the FreeNAS control panel). Can someone point me towards the right way to do this? I've looked around and can't find the FreeNAS logging documentation.

Can I just pipe/append stdout to /var/log/maillog?

Thanks!




#!/usr/local/bin/bash
set TRANSFERS=32
set DATE=`date +%e-%m-%y`
res=$(ps -A -ef -o comm | grep -e rclone)
if [ "$res" == "rclone" ]
then
echo "rclone currently running. Aborting backup."
else
echo "rclone not currently running. Starting backup."
rclone sync /media/myfiles BBencrypted:myfiles --transfers=32 --log-level=NOTICE --log-file=/root/rcloneLog/rcloneLog-$DATE.log --ask-password=false
fi
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
The easiest option would be to just have your script called by cron. The output of the command will be emailed to the same address that you have configured.
 

gsk3

Cadet
Joined
Sep 12, 2017
Messages
5
It is being run through cron. Thus far no output has appeared in the daily emails.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
You wouldn't see it in the daily email, you would get a separate message for every run of the command. What does the cron config look like for this entry?
 

gsk3

Cadet
Joined
Sep 12, 2017
Messages
5
Looks like this:
Code:
# Run backups nightly														   
1	   4	   *	   *	   *	   root	/root/backup_rclone.sh


I realized it's in a jail, which duh is probably why it's not working with standard email logging. Any way to pass it out of the jail to the central system's logging/email mechanism?

Thanks.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
I can't think of a way to pass the jail output to the host logging and email.
You could instead make rclone available to the FreeNAS host (is rclone a standalone binary? or does it bring a lot of dependencies?)
Or you could configure email in the jail. This really isn't that extensive. I have the steps written down that I use with my jails that I can post later today.
 
Status
Not open for further replies.
Top