Running cronjobs in Azure App Service Linux

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.

To schedule a cronjob on azure app service Linux web application you can follow the steps outlined below,

 

karthi_0-1680854376464.png

 

Navigate to “SSH” from azure app services portal and click on Go ->

 

karthi_1-1680854376469.png

 

karthi_2-1680854376472.png

 

Create a script file in /home with name as start.sh and add the below lines to the script file and save the file.

Command to create a script file - touch /home/start.sh

Open the file using vim editor: vi /home/start.sh and copy the below code

 

# Installing cron apt-get update -qq && apt-get install cron -yqq # Starting cron service cron start #cron scheduler (crontab -l 2>/dev/null; echo "* * * * * find /home/BackupLogs -type f -size 1k -delete ")|crontab

 

Post that, you can add the created script as a startup command which would install the cron, start the cron and schedule the cron during startup. To add as a startup command, navigate to Azure portal -> Configuration blade -> General settings tab and provide as below,

 

 

karthi_3-1680854376476.png

 

 

In the above sample code, it checks for all the files with size 1KB in /home/BackupLogs and delete them for every minute.

 

Based on your convenience you can adjust the CRON scheduler time and command

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.