How do I run Cronjobs on Linux App Service

BheeshamLohana 1 Reputation point
2022-07-18T03:57:50.03+00:00

I have configured startup script as well as configured the cron job manually within Linux Container running PHP app. The script is set properly and when running the script manually from within container it is working as expected but the cron schedule do not work.

I am also not able to find the cron job logs to check for any errors.

I installed cron as follows;

Installing cron

apt-get update -qq && apt-get install cron -yqq

service cron start

mkdir /home/BackupLogs

(crontab -l 2>/dev/null; echo "*/5 * * * * cp /home/LogFiles/*.log /home/BackupLogs")|crontab

Reference: https://social.msdn.microsoft.com/Forums/azure/en-US/c8dddaea-a185-4294-9ba3-1224d1cf98ec/how-do-i-run-cronjobs-on-linux-app-service?forum=windowsazurewebsitespreview

It would be great if someone can direct me to the right path. What wrong I am doing here?

Where do I find the cron job logs as well. Under /var/log I do not see syslog file or any log file related to cron.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,022 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dulce Selene Arzola Valenzuela 6 Reputation points
    2022-12-12T23:20:25.213+00:00

    @BheeshamLohana Did you solve the issue, and would you be so kind as to share your cron configuration script, please?

    1 person found this answer helpful.

  2. brtrach-MSFT 16,686 Reputation points Microsoft Employee
    2022-07-19T05:09:27.647+00:00

    @BheeshamLohana Thank you for your question regarding cronjobs on Linux App Services.

    Since the steps provided for a Linux blessed image app service did not work and you mention using a Linux container, I am going to assume you are using a custom container Linux app service. The steps to use cronjobs are different in this situation.

    To Enable cron, add the following line to Dockerfile:

    RUN apt-get install -yqq cron  
    

    And following line in the container init script (init_container.sh)

    (crontab -l && echo "* * * * * echo 'hello from cron' >> /home/site/wwwroot/cron1.txt")|crontab  
    

    In this case we will write “hello from cron” to file /home/site/wwwroot/cron1.txt every minute. You can replace this with anything else you wish to run periodically.

    echo 'hello from cron' >> /home/site/wwwroot/cron1.txt  
    

    Please let us know if this approach helps to resolve your requirement. If not, please let us know so we can assist you further.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.