Forum Discussion
Steps to configure cron jobs to execute commands | F5 BIG IP LTM 13.X
Hi All,
I need help to configure cron job to run below two commands on hourly basis. Could you please help me with the steps:
tmsh run cli script certificatereports.tcl > /var/tmp/cert-outputs.txt
echo "Message Body Here" | mailx -s "Subject Here" -a cert-outputs.txt YourMail-ID
Regards,
Sumit D
Had this replied yesterday in the codeshare, nevertheless will add the same comment here - hoping it could help someone in future.
Hi Sumit,
Apologies on the late reply, Good to know that you already have smtp set.
The next easy step is to put a small script with any mail agent (sendmail or mail or mailx) and have that script run on cron for every month.
Goto /var/tmp/ and create a file as automatecertificatereports.sh.
Add the below code inside the automatecertificatereports.sh file.
#!/bin/sh tmsh run cli script certificatereports.tcl > /var/tmp/cert-outputs.txt from="abc@domain.com" to="abc@domain.com,pqr@domain.com,xyz@domain.com" subject="Automated SSL Certificate Report" mail -s "$subject" -r "$from" -a "/var/tmp/cert-outputs.txt" "$to" << EOF Hi Team, Please find the attached SSL Certificate Report. Thanks & Regards, abc@domain.com EOF
Change the permission to executable one.
chmod +x automatecertificatereports.sh
Now goto your crontab & do a list first to see the existing cron jobs running.
crontab -l
You should see some couple of disk monitors check etc etc.
Always put some good comments before you make an entry of your cronjob, Use crontab -e to edit/add your entries.
crontab -e
Goto the of the section and the below 2 lines,
## Section for Automated SSL Certificate Report - Monthly Cron - Start of month - 6 O'clk ## 0 6 1 * * /usr/bin/bash /var/tmp/automatecertificatereports.sh
You can edit this cron value according to your need. For testing, try running this for every day 1 AM report - 0 1 * * *
Hope this helps. Let us know if you have more concerns.
Had this replied yesterday in the codeshare, nevertheless will add the same comment here - hoping it could help someone in future.
Hi Sumit,
Apologies on the late reply, Good to know that you already have smtp set.
The next easy step is to put a small script with any mail agent (sendmail or mail or mailx) and have that script run on cron for every month.
Goto /var/tmp/ and create a file as automatecertificatereports.sh.
Add the below code inside the automatecertificatereports.sh file.
#!/bin/sh tmsh run cli script certificatereports.tcl > /var/tmp/cert-outputs.txt from="abc@domain.com" to="abc@domain.com,pqr@domain.com,xyz@domain.com" subject="Automated SSL Certificate Report" mail -s "$subject" -r "$from" -a "/var/tmp/cert-outputs.txt" "$to" << EOF Hi Team, Please find the attached SSL Certificate Report. Thanks & Regards, abc@domain.com EOF
Change the permission to executable one.
chmod +x automatecertificatereports.sh
Now goto your crontab & do a list first to see the existing cron jobs running.
crontab -l
You should see some couple of disk monitors check etc etc.
Always put some good comments before you make an entry of your cronjob, Use crontab -e to edit/add your entries.
crontab -e
Goto the of the section and the below 2 lines,
## Section for Automated SSL Certificate Report - Monthly Cron - Start of month - 6 O'clk ## 0 6 1 * * /usr/bin/bash /var/tmp/automatecertificatereports.sh
You can edit this cron value according to your need. For testing, try running this for every day 1 AM report - 0 1 * * *
Hope this helps. Let us know if you have more concerns.
Hello Sumit.
You should configure one script file and place it on this location
/etc/cron.hourly/yourscript
yourscript:
#!/bin/bash tmsh run cli script certificatereports.tcl > /var/tmp/cert-outputs.txt echo "Message Body Here" | mailx -s "Subject Here" -a cert-outputs.txt YourMail-ID
You should also change the permission (execute)
chmod a+x yourscript
Here is a F5 official reference
REF - https://support.f5.com/csp/article/K33730915
IMPORTANT: Take into account that those scripts are not migrating in case of upgrading
F5 gives you the chance to configure periodically executed scripts using iCalls, which is a native F5 solution.
REF - https://devcentral.f5.com/s/articles/what-is-icall-27404
KR,
Dario.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com