Schedule tasks under Linxu for R
Frequently encountered, we need to schedule tasks: run task automatically! To schedule your R task, edit /etc/crontab like this:
sudo nano /etc/crontab
At the end of the opened file, add such a line:
0 * * * * username Rscript /var/shiny-server/www/Project/load_data.R
Where 0 * * * *
is the cron formula to schedule your task. The above one means run the followed command per hour at 0 minute. The username is your logged name. Sometimes, the scheduled task doesn’t run, then we should check two issues:
-
Is the shell command correct? To check it, just paste the shell command (e.g. Rscript /var/shiny-server/www/Project/load_data.R) in the terminal. If it works, then go to the next step:
-
Permission mode. Some files have strict permission, it allow only special users to execute. To check the perission, run the following command in termial:
sudo ls -l /var/shiny-server
Pleasetake a look how the permissons were defined under Linux. We can change the permission mode using the following command:
sudo chmod - R 777 /var/shiny-server/