

This allows the mail command to connect to Gmail’s SMTP server using your Gmail credentials. Once you’ve done that, you can use the mail command to send email from your script.įollow these steps to set up the mail and cron job:Įnable Less Secure Apps: First, you need to enable less secure apps in your Gmail account settings. You will need to configure your EC2 instance to use your email service provider’s SMTP server and provide SMTP credentials (username and password). If you don’t have a mail server, you can use a third-party email service like Gmail, Amazon SES, etc…Here we are using Gmail for mail sending. To use the mail command, you need to have a mail server installed on your EC2 instance. Run the script manually using bash container-status-check.sh command. You can also add a line to the script that will start the container if it is not running, after sending the email alert.


Sending email."Įcho "Container $CONTAINER_NAME is not running on $(hostname)." | mail -s "$CONTAINER_NAME Container not running" $EMAIL_TOĮcho "Container $CONTAINER_NAME is running."Ĭhange and accordingly. If ! docker ps | grep $CONTAINER_NAME > /dev/null thenĮcho "Container $CONTAINER_NAME is not running.
