1

I wrote a .jar file that is supposed to be run once a day that interacts with Google App Engine. When I run it from the computer, it runs just fine and creates a logfile that details some statistics. I transferred it over to the Raspberry Pi and it runs via crontab.

The first time I ran it, I got a permission denied in syslog. I read that using 'sudo crontab -e' would fix that. Now I no longer get the error but my logfile doesn't appear.

Here is the portion of the code that is to create the logfile:

        PrintWriter writer = new PrintWriter("log" + format.format(date) + ".txt");
        writer.println("Total Themes: " + numThemes + "\r\n");
        writer.println("Active Themes: " + numActiveThemes + "\r\n");
        writer.println("Inactive Themes: " + numInactiveThemes + "\r\n");
        writer.println("Total Sales: " + numSales + "\r\n");
        writer.println("Total Price Changes: " + numPriceChanges + "\r\n");
        writer.println("Total Time: " + seconds + " seconds" + "\r\n");
        writer.close();

Crontab:

0 2 * * * java -jar /mnt/data/scripts/test.jar

What am I missing about the switch from Windows that is preventing the creation of the logfile?

Edit: I can run the .jar file manually (using sudo) and the logfile is created. Not working w/cron though.

Edit2: /etc/log/syslog has:

Feb  8 21:46:01 raspberrypi /USR/SBIN/CRON[10841]: (root) CMD (java -jar /mnt/data/scripts/updater_pricing.jar

Edit 3: Changed permissions of the folder and jar to 777 (as a test). Now I can run the file w/o 'sudo' (expected). Tried running a regular cron task using the same cron expression as above. Now syslog has:

Feb  9 07:55:01 raspberrypi /USR/SBIN/CRON[13292]: (pi) CMD (/usr/bin/java -jar /mnt/data/scripts/test.jar)

It also has: Feb 9 07:55:59 raspberrypi /USR/SBIN/CRON[13291]: (CRON) info (No MTA installed, discarding output)

Perhaps I can add something that will output the error message?

7
  • What user is running the cronjob and do they have permissions to write in the given directory?
    – Jacobm001
    Feb 9, 2015 at 4:05
  • How do I find out what user? I logged in via the default user "pi" via ssh and did 'sudo crontab -e' I tried changing the permissions of the folder 'scripts' to 777 but appear to get the same result.
    – easycheese
    Feb 9, 2015 at 4:07
  • Running crontab under sudo can do some strange things... Does the command need root privileges? If not try removing it from that file and run 'crontab -e'. This will run under the user "pi" and may be less error prone.
    – Jacobm001
    Feb 9, 2015 at 4:41
  • It needs to create a file, doesn't that need sudo permissions?
    – easycheese
    Feb 9, 2015 at 12:13
  • 1
    crontab sends errors through your system's mail client. I would suggest installing postfix and configuring it with the smtp service of whatever you use as an email client. Example: rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp try that and let us know what error you're getting.
    – Jacobm001
    Feb 9, 2015 at 16:04

1 Answer 1

1

Figured it out thanks to the pointers from @Jacobm001. The email was being sent because I had some lines of System.out.println()

The logfiles were being created, just in the wrong place. I had to modify the original file line to be:

PrintWriter writer = new PrintWriter("/mnt/data/scripts/" + "log" + format.format(date) + ".txt");
1
  • 1
    Congrats, glad to hear you got it working!
    – Jacobm001
    Feb 11, 2015 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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