muquit / mailsend

A program to send mail via SMTP from command line
Other
294 stars 68 forks source link

No log No send when it's in rc levels #95

Closed rikhtehgaran closed 8 years ago

rikhtehgaran commented 8 years ago

i want to mail some log from server so i use mailsend in script and put in rc run levels for when boot email could be send. so i did these steps: Put mailsend script

# vim /etc/init.d/mymail
# chmod 755 /etc/init.d/mymail

Test it. it works and i get email

# /etc/init.d/mymail
Message: Something
Mime type: text/plain
Disposition: inline
Encoding type: none

Mail sent successfully

Also in log:

# cat /var/log/decrypt_mail_log
23-Mar-2016 21:03:56.109: mailsend v@(#) mailsend v1.18
23-Mar-2016 21:03:58.591: Mail sent successfully

Now run this:

# update-rc.d mymail defaults 93 93
update-rc.d: warning: /etc/init.d/mymail missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/mymail ...
   /etc/rc0.d/K93mymail -> ../init.d/mymail
   /etc/rc1.d/K93mymail -> ../init.d/mymail
   /etc/rc6.d/K93mymail -> ../init.d/mymail
   /etc/rc2.d/S93mymail -> ../init.d/mymail
   /etc/rc3.d/S93mymail -> ../init.d/mymail
   /etc/rc4.d/S93mymail -> ../init.d/mymail
   /etc/rc5.d/S93mymail -> ../init.d/mymail

Remove log and reboot and im waiting for receive email

# rm /var/log/decrypt_mail_log
# reboot

so no email and no log after reboot:

# cat /var/log/decrypt_mail_log
cat: /var/log/decrypt_mail_log: No such file or directory
muquit commented 8 years ago

It could be a path issue. Use absolute paths in your mymail script. It appears that the script bailed out and did not call mailsend or exited before calling mailsend. I created a mymail script as shown below, set it up the way your did in an ubuntu system and it works fine as expected. Thanks.

# cat /etc/init.d/mymail
#!/bin/sh

# muquit@muquit.com Mar-23-2016
MAILSEND="/usr/local/bin/mailsend"
LOG_FILE="/var/log/mymail.log"
RUNLEVEL=`/sbin/runlevel`
DATE=`/bin/date`
echo "${DATE} starts-- ">> ${LOG_FILE}
echo "Run level: ${RUNLEVEL}" >> ${LOG_FILE}
${MAILSEND} -V >> ${LOG_FILE} 2>&1
echo "${DATE} ends-- ">> ${LOG_FILE}

After reboot:

# cat /var/log/mymail.log
Wed Mar 23 16:33:49 EDT 2016 starts--
Run level: 2 6
mailsend Version: @(#) mailsend v1.18
Compiled with OpenSSL: OpenSSL 1.0.1c 10 May 2012
Wed Mar 23 16:33:49 EDT 2016 ends--
Wed Mar 23 16:34:41 EDT 2016 starts--
Run level: N 2
mailsend Version: @(#) mailsend v1.18
Compiled with OpenSSL: OpenSSL 1.0.1c 10 May 2012
Wed Mar 23 16:34:41 EDT 2016 ends--
rikhtehgaran commented 8 years ago

Thanks it worked