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: 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 | 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 
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 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 ......" | mail \
-r "From: alertAdmin <>" \
-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 <>" \
-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.