Preparation

  1. Make sure that you have ffp/funplug installed
  2. Login to your DNS-323 (if there is no shell prompt write 5784468 to get it)
  3. Create two files /mnt/HD_a2/ffp/start/crontab_update and /mnt/HD_a2/ffp/bin/do_sth.sh and make it executable (read whole post)
  4. Reboot NAS, or run /mnt/HD_a2/ffp/start/crontab_update start
  5. You should be done

crontab_update init script for ffp

Location: /mnt/HD_a2/ffp/start/crontab_update

Make it executable: chmod +x /mnt/HD_a2/ffp/start/crontab_update

Contents of crontab_update:

#!/ffp/bin/sh

# PROVIDE: crontab_update

# REQUIRE: LOGIN

#

# Email settings are taken from webadmin!

#

. /ffp/etc/ffp.subr

name="crontab_update"

start_cmd="crontab_update_start"

## CHANGES SECTION

# You must CHANGE settings below

SMTP=smtp.mail.com

USER=user@mail.com

SOURCE=user@mail.com

DEST=dest@mail.com

PASS=secret

## END OF CHANGES

crontab_update_start() {

CRONTXT=/tmp/crontab.txt

# start with existing crontab

/bin/crontab -l > $CRONTXT

# add the Rsync job to execute at 2:05 am - also create a logfile

/bin/echo "0 20 * * 1-4 /mnt/HD_a2/ffp/bin/do_sth.sh &" >> $CRONTXT

/bin/echo "15 16 * * 5 /mnt/HD_a2/ffp/bin/do_sth.sh &" >> $CRONTXT

# We are now booting - send test email and enable mail

if [ ! -e /.msmtprc -o ! -e /.muttrc ] ; then

        email -m 63 -h $SMTP -p 25 -a 1 -u $USER -w $PASS -s $SOURCE -d $DEST -t

        test -e /home/root/.msmtprc && ln -s /.msmtprc /home/root/

        test -e /home/root/.muttrc && ln -s /.muttrc  /home/root/

fi

# install the new crontab

/bin/crontab $CRONTXT

# clean up tmp crontab

/bin/rm $CRONTXT

}

run_rc_command "$1"

do_sth script

Location: /mnt/HD_a2/ffp/bin/do_sth.sh

Make it executable: chmod +x /mnt/HD_a2/ffp/bin/do_sth.sh

Contents of: /mnt/HD_a2/ffp/bin/do_sth.sh

#!/bin/sh

#

# Simple script to do something

#

PATH=/mnt/HD_a2/ffp/bin/:$PATH

SRC_PATH='/mnt/HD_a2'

SPACE_REMAINING=`df -h`

RESULT=$?

echo -e "Process ended with result ===> $RESULT\n"\

"Space remaining:\n\n"\

"$SPACE_REMAINING"\

"\n\n"\

"Your DNS-323 (dlink-storage)"\

| mutt -s "Process status ("`date -I`")" dest@mail.com

How this can be improved?

Think about cat /tmp/tmp_send.mm | mutt -s dlink-storage_E-Mail_Alert dest@mail.com

How I've figured this out?

Made strings /sys/crfs/web and found email -h %s -p 25 -a 1 -u %s -w %s -s %s -d %s -t rest was just a matter of time - to get to know how to use it correct.

Common mistakes

http://blog.0x1fff.com/2009/11/howto-send-email-from-bash-on-dlink-dns.html (thank you, 0x1fff)