I have a shell script with the following content

sudo Rscript /home/username/RWD/test.R
sudo find /home/username/RWD -type f -name "*.png" -exec /usr/bin/mpack -s "Test Mail" {} my.email@provider.de \;
sudo find /home/username/RWD -type f -name "*.png" -exec rm -f {} \;

So I just execute a R script which produces an image file (*.png). This file is send via mail and deleted afterwards.

This works fine when I execute the script in the command line. But when I use cron to schedule the script, the content of the mail is what R is printing in its console:

Lade nötiges Paket: xml2

Attache Paket: ‘zoo’

The following objects are masked from ‘package:base’:

   as.Date, as.Date.numeric

1: Removed 3 rows containing missing values (geom_point). 
2: Removed 5 rows containing missing values (geom_point).

Any idea why the scheduled script behaves differently?

  • I don't think that cron will be able to guess that it should execute everything in the same current working directory and keep the state of the CWD. cron does limit the CWD considerably. Instead do an mktemp -d and place the file in there (pass the result of mktemp to each part of the script). – grochmal Mar 5 '17 at 1:13
  • @grochmal Ok thanks. I will give it a shot. – Martin Schmelzer Mar 5 '17 at 9:00
  • @grochmal Since I am a shell noob I didn't really got the mktemp attempt working. I now ended up with calling cd /home/username/RWD && {MYCODE} prior to every line in my shell script. That works for me right now. Thank's for guiding me towards the CWD problem! (If you want to work your mktemp comment out as an answer, I will gladly accept it). – Martin Schmelzer Mar 6 '17 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.