Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I tried to set up a cronjob on my server. Actually this command should execute a java programm every hour. But somehow this didn't worked. I googled and tried to set up a test-script that should run every minute so I could see if my cronjob works.

If I execute the script from the shell there is no problem.

ps ax| grep cron

prints the following

1147 ?        Ss     0:00 cron
13940 pts/0    S+     0:00 grep --color=auto cron

my crontab -l:

# m h  dom mon dow   command
30 * * * * root java -jar -Xss100m /home/crawler/WebCrawler.jar
1 * * * * root /home/crawler/test.sh

the test.sh:

#!/bin/bash

echo "this is a test " >> test.txt

Does anyone got an idead whats maybe wrong with my system and the crontabs i set up? Its an ubutnu 10.04 server (because the hoster I use got problems with his virtualization and due to that 10.04 is the only version that runs the jvm properly :/)

share|improve this question

migrated from stackoverflow.com Dec 6 '12 at 12:06

This question came from our site for professional and enthusiast programmers.

    
Do you know what -Xss parameter stands for? :) –  Andrew Logvinov Dec 6 '12 at 8:46
    
Did the test.sh cron execute as expected. I guess you need to remove the root word from the start of command. Never seen that before. –  mtk Dec 6 '12 at 8:51
    
iirc -xss set a stack size for the thread. test.sh execute as expected if I start it from the shell with ./test.sh. I removed the root from the crontab but it still does not execute. –  Ogofo Dec 6 '12 at 8:59
    
can you check your mails? I mean enter mail in unix/terminal and check if there are any mails, in it. If there is check what does it say? –  Vishal Dec 6 '12 at 9:09
    
Alright. Totally forgott that cron spams my mail if it got errors. Cron seems to not have problems with executing the test.sh because there is no mail mentioning this file. But it got problems with the java command. It feels like the cronjob is not executing the process in the /home/crawler/ directory. The crontab is unable to find the COnfig.cfg the java programm needs and which is in then /home/crawler/ directory and it is not able to execute casperjs which ia dded to the path via my bashrc. Some ideas? –  Ogofo Dec 6 '12 at 9:17

1 Answer 1

up vote 2 down vote accepted

Remove the word 'root'. It should look like this:

1 * * * * /home/crawler/test.sh

That should work, if the user that runs cron has enough privileges to run the script.

share|improve this answer
    
Alright. I already tried this. But it seems that the crojob is not executed in the directory the script ist, therefore I'm unable to find the output. –  Ogofo Dec 6 '12 at 9:20
    
I think by default Crontab runs from your home directory. But I'm not sure. You can fix it anyway by specifying the output in the script with a full path: echo "this is a test " >> /tmp/test.txt or by doing a cd before the cron command: 1 * * * * cd tmp && /home/crawler/test.sh or doing the cd as the first command in your script, and then the echo statement. –  Alex Dec 6 '12 at 9:22
    
somehow neither 1 * * * * cd /home/crawler& && test.sh nor inserting cd /home/crawler/ into the test.sh seesm to work :( –  Ogofo Dec 6 '12 at 9:35
    
And the users that runs crontab can execute the script? p.s. You realize this makes it run once an hour right? (1 * * * *). I don't know how you are testing this but you didn't wait an hour before posting here again ;-). –  Alex Dec 6 '12 at 9:40
    
alright ... I think i mixed up a lot of thinks :D 0-59 works fine with cd /home/crawler& && test.sh. Thank you very much for helping me this morning :) –  Ogofo Dec 6 '12 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.