7

I am trying to schedule a cronjob to execute an R Script in a linux server. I have achieved to type the commands in the server manually and it works. To do so i have to type the following commands:

  1. root@debian:~# cd /home/script2
  2. root@debian:/home/script2# Rscript scriptSecos.R

How can i specify a cronjob that will execute the previous commands, once a day?

Thank you.

3 Answers 3

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

7

The following cron job will run Rscript scriptSecos.R from the path /home/script2, once a day, at 0:00 (midnight).

0 0 * * * cd /home/script2; Rscript scriptSecos.R >/dev/null 2>&1

If you want to save the output of the script to a file, change >/dev/null with >/path/to/file.

You can copy and paste this cronjob in your crontab file (You can open the file by using command crontab –e)

4
  • Thank you! In that string, what is the string ">/dev/null 2>&1" doing? Jun 18, 2015 at 12:53
  • 2>&1 : redirects stderr (errors) to stdout (normal output). >/dev/null hides all messages. The 2>&1 expression is useful when you want to save both the errors and normal output to a file. That's way I added it, so it is easy for you to do it if you want.
    – henfiber
    Jun 18, 2015 at 13:36
  • I used this string and worked perfectly! Thank you henfiber Jun 18, 2015 at 17:58
  • I must insist how important it is to first do cd to your folder! Because if your script cals anything in this folder it will fail. Thank you
    – denis
    Jul 5, 2020 at 21:33
0

The following site provides useful reference information for crontab

http://www.adminschoice.com/crontab-quick-reference

With your example, the following will run the job at 3 am everyday.

00      03      *       *       *       Rscript /home/script2/scriptSecos.R
0

add cron as below.

eg:

15 23 * * * Rscript /home/script2/scriptSecos.R  >/dev/null 2>&1

you have to mention running script type.Then allow cron logs and check its running or not

Not the answer you're looking for? Browse other questions tagged or ask your own question.