Using rundeck scheduler to set up sending mail

Posted by shivangp on Sun, 03 May 2020 23:51:10 +0200

1. Configure QQ mailbox to send mail

1.1 enable the SMTP service and obtain the authorization code

1.2 select account

  • Start related services and generate authorization code

2. Enable sendmail service and postfile service

[root@zydatahadoop001 rundeck]# service sendmail stop
[root@zydatahadoop001 rundeck]# chkconfig sendmail off

[root@zydatahadoop001 rundeck]# service postfix start
[root@zydatahadoop001 rundeck]# chkconfig postfix on

If postfix start fails

 [root@rzdatahadoop002 ~]# postfix check

postfix: error while loading shared libraries: libmysqlclient.so.16: cannot open

shared object file: No such file or directory [root@rzdatahadoop002 ~]# rpm -qa|grep mysql [root@rzdatahadoop002 ~]# yum install mysql-libs

3. Create certificate

[root@zydatahadoop001 rundeck]# mkdir -p /root/.certs/

[root@zydatahadoop001 rundeck]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt

[root@zydatahadoop001 rundeck]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt 

[root@zydatahadoop001 rundeck]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt 

[root@zydatahadoop001 rundeck]# certutil -L -d /root/.certs

[root@zydatahadoop001 rundeck]# cd /root/.certs

4. Add the following at the end of the / etc/mail.rc file

set from=own qqQQ@qq.com 
set smtp=smtp.qq.com 
set smtp-auth-user=own QQ
#Authorization code
set smtp-auth-password=(Own authorization code) 
set smtp-auth=login
set smtp-use-starttls set ssl-verify=ignore
set nss-config-dir=/root/.certs

Note: there must be no spaces before and after the equal sign.

5. Command line verification mail service

[root @ zydatahadoop 001 rundeck] 3535; echo Hello word | mail - s "title" own QQ@qq.com

qq will receive an email
Email without attachment

echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is $RUNNINGNUM in 192.168.137.201 ......" | mail \
-r "From: alertAdmin <QQ@qq.com>" \
-s "Warn: Skip the new $JOB_NAME spark job." ${EMAIL}

//Email with attachments

echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail sql attachement." | mailx \
-r "From: alertAdmin <QQ@qq.com>" \
-a $FAILSQL_MONITOR_CURRENT/merge${CURRENT_TIME_SHORT}.log \ 
-s "Critical:KSSH fail sql." ${EMAIL}
  • At this time, you can write the mail content into the shell script and use the rundeck tool to schedule it.

Topics: MySQL SSL SQL RPM