Use the vim text editor to create the file:
sudo vim /etc/cron.daily/autoupdateNote: If you're not familiar with vim, you can use nano or any other text editor instead.
Save and exit the file.
Here's a script for OS Update with Dist-upgrade:
#!/bin/sh
{
echo "Auto update started on $(date)"
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get autoclean
sudo apt-get autoremove -y
echo "Auto update completed on $(date)"
} >> /var/log/autoupdate.log
mail -s "Auto update report for Server :Website_API_10.4.0.230 $(date)" -a "From: [email protected]" [email protected] < /var/log/autoupdate.logOr use this script for Dist-upgrade only:
#!/bin/sh
{
echo "Auto update started on $(date)"
sudo apt-get update
sudo apt-get upgrade -y
echo "Dist-upgrade started on $(date)"
sudo apt-get dist-upgrade -y
echo "Dist-upgrade completed on $(date)"
sudo apt-get autoclean
sudo apt-get autoremove -y
echo "Auto update completed on $(date)"
} >> /var/log/autoupdate.log
mail -s "Auto update report for Server :Subject Name/Server Details $(date)" -a "From: [email protected]" [email protected] < /var/log/autoupdate.logRemember to replace [email protected] with your actual email address.
sudo chmod +x /etc/cron.daily/autoupdateSave and exit the file.
sudo apt-get install mailutils -y && sudo apt-get install s-nailsudo apt-get install postfixTo open the configuration file:
sudo vim /etc/postfix/main.cfComment the line:
#relayhost =Add the following lines to the end of the file:
relayhost = [smtp.office365.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crtSave and exit the file.
sudo vim /etc/postfix/sasl_passwd
[smtp.office365.com]:587 [email protected]:YourPasswordReplace [email protected]:YourPassword with your actual email address and password.
sudo chown root:root /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwdsudo systemctl restart postfixsudo postmap /etc/postfix/sasl_passwdecho "This is a test email body." | mail -s "Test Email Subject" -a "From: [email protected]" [email protected]Replace [email protected] and [email protected] with your actual email addresses.
sudo apt-get install clamav clamav-daemon -ysudo freshclamTo start, enable, check the status, stop, disable, and restart the freshclam service, use these commands respectively:
sudo systemctl start clamav-freshclam
sudo systemctl enable clamav-freshclam
sudo systemctl status clamav-freshclam
sudo systemctl stop clamav-freshclam
sudo systemctl disable clamav-freshclam
sudo systemctl restart clamav-freshclamEdit the CRONTAB configuration file:
sudo crontab -eSchedule a cron job to run a weekly virus scan on the server's root directory. Log results to /var/log/clamscan.log, and send an email report from [email protected] to your email. Don't forget to replace [email protected] with your actual email address.
0 1 * * SUN sudo clamscan -r -i / | tee -a /var/log/clamscan.log | mail -s "Clamscan_Output_Website_API_10.4.0.230" -a "From: [email protected]" [email protected]Save and exit the file.
To manually scan your system for viruses and get a list of infected files:
sudo clamscan -r -i /After you review the list of infected files and decide you want to remove them, you can run:
sudo clamscan -r --remove /2. Insert this line in the crontab to automatically renew certbot and send an email after completion:
0 2 * * * /usr/bin/certbot renew --quiet; echo "Certbot renewal job completed" | mail -s "Certbot Renewal Output" -a "From: [email protected]" [email protected]Don't forget to replace [email protected] with your actual email address.
That's it! Remember to check the logs (/var/log/autoupdate.log and /var/log/clamscan.log) from time to time to ensure everything is running smoothly. Use cat /var/log/autoupdate.log and cat /var/log/clamscan.log to display these logs.