email at startup

Tell us your most wanted features from QNAP products.
Post Reply
hallohome
Getting the hang of things
Posts: 56
Joined: Wed Apr 16, 2008 1:12 am

email at startup

Post by hallohome »

is there a way to send a notification right after the start of my Qnap 639 ?? I (and some users) start the Qnap over WOL and I want a email that the device is ready. Is there a way to do this ?? If not I think it is a nice feature for office Admins Like me, because every time someone Wakes the Qnap I have an Email.
cybergull
New here
Posts: 8
Joined: Sat Feb 09, 2013 5:31 pm

Re: email at startup

Post by cybergull »

+1
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: email at startup

Post by pwilson »

hallohome wrote:is there a way to send a notification right after the start of my Qnap 639 ?? I (and some users) start the Qnap over WOL and I want a email that the device is ready. Is there a way to do this ?? If not I think it is a nice feature for office Admins Like me, because every time someone Wakes the Qnap I have an Email.
Easy to do already. Simply create your "autorun.sh" file on your NAS. See QNAPedia article: Running Your Own Application at Startup; (Use the MTD method, despite what the Wiki says).

Assuming that your SSMTP Server on the NAS is properly configured, and you can successfully send test notification e-mails. The following script would do it for you.

(Note you will need to modify the SendTo, SendFrom, and (possibly Subject) variables at the top of the script

/share/homes/admin/bin/wol-notify.sh

Code: Select all

#!/bin/sh
#
# wol-notify.sh - aka /share/homes/admin/bin/wol-notify.sh
#
#  This script e-mails the designated recipient upon NAS Startup. 
#  See QNAP Forum article: http://forum.qnap.com/viewtopic.php?f=24&t=99093
# 
SendTo="me@somewhere.com"
SendFrom="TS-639@XXXXXX.myqnapcloud.com"
Subject="$(/bin/hostname) started at: $(/bin/date)" 
#
rm -f /tmp/wol-notify.email
touch /tmp/wol-notify.email
echo "From: ${SendFrom}"     >>/tmp/wol-notify.email
echo "To: ${SendTo}"         >>/tmp/wol-notify.email
echo "Subject: ${Subject}"   >>/tmp/wol-notify.email
echo " "		     >>/tmp/wol-notify.email
cat <<EOF >>/tmp/nasreport
echo "NAS Model:      $(getsysinfo model)"
echo "Firmware:       $(getcfg system version) Build $(getcfg system 'Build Number')"
echo "System Name:    $(/bin/hostname)"
echo "Workgroup:      $(getcfg system workgroup)"
echo "Base Directory: $(dirname \$(getcfg -f /etc/config/smb.conf Public path))"
echo "NAS IP address: $(ifconfig $(getcfg network 'Default GW Device') | grep addr: | awk '{ print $2 }' | cut -d: -f2)"
echo " " 
EOF
cat /tmp/wol-notify.email | /usr/sbin/sendmail -t 
rm -f /tmp/wol-notify.email
echo "Done." 
#done

If you save this script to the same location and make it executable, you can run if from the command line as often as you want, and you can run this from your "autorun.sh" file at every restart.

Code: Select all

chmod +x /share/homes/admin/bin/wol-notify.sh


Test this script from the command line, and modify it to your own specifications. When you get the desired output (ie an e-mail from the NAS) successfully, you can add this to your "autorun.sh" file so that it "auto-runs" at every Startup.

Code: Select all

#!/bin/sh
#
# NAS Autorun.sh file
#
touch /tmp/autorun.ran
/share/homes/admin/bin/wol-notify.sh
#done

You can create this autorun.sh file on your NAS with:

Code: Select all

#!/bin/sh
#
#  Create the "autorun.sh" file on my TS-639 Pro
#
mount /dev/sdx6 /tmp/config
touch /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
cat << EOF >> /tmp/config/autorun.sh
#!/bin/sh
#
# NAS Autorun.sh file
#
touch /tmp/autorun.ran
/share/homes/admin/bin/wol-notify.sh
#done

EOF
umount /tmp/config
#done


Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Post Reply

Return to “Features Wanted”