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 have this FeedIndexer.sh:

#!/bin/sh java -jar FeedIndexer.jar

Just to run FeedIndexer.jar which is in the same directory as the .sh, I would like to run it using crontab, so I did this:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
01 01 * * * root run-parts --report /home/slosada/workspace/FeedIndexer/target/FeedIndexer.sh
#

But I don't know how to run it. Have I made any mistake?

share|improve this question

migrated from stackoverflow.com May 27 '10 at 23:43

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

    
Probably should be on ServerFault. But also, what do you mean by "doesn't work"? Are you getting an error message? Does nothing happen at all? –  Jacob Mattison May 27 '10 at 14:49
1  
Are you sure you can put an instruction right after the sha-bang? tldp.org/LDP/abs/html/sha-bang.html#MAGNUMREF says: This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line) –  Alberto Zaccagni May 27 '10 at 14:50
    
No, my problem is that I don't know hoy to run it... –  Blanca May 27 '10 at 14:51
    
That's the third time you've said "I don't know how to run it". Run what? You don't run crontabs, the cron daemon parses them and runs the commands at whatever time period you specified –  Michael Mrozek May 27 '10 at 14:58
    
So, i don't have to do anything more?? but .jar is not being executed –  Blanca May 27 '10 at 15:01
show 2 more comments

3 Answers

You don't need the run-parts part. run-parts is used to run every script in a certain directory, and you only need to run one script, which is handled by cron itself. So, this should work:

01 01 * * * root /home/slosada/workspace/FeedIndexer/target/FeedIndexer.sh
share|improve this answer
add comment

Have you tried using single-digit hour and minute fields:

1 1 * * * 
share|improve this answer
    
Ok, but how could it try it?? I mean, how would I run it?? –  Blanca May 27 '10 at 14:50
    
You could replace each 01 with 1 and wait an hour, or adjust them to be 1 * * * * to run the script on the first minute of each hour, for example. Here is a quick reference: adminschoice.com/crontab-quick-reference –  Justin Ethier May 27 '10 at 14:54
    
Thank you, that manual is really interesting about different possibilities, but i don't know yet what must i type in the terminal... –  Blanca May 27 '10 at 14:57
    
I am very confused. There is a crontab file under /etc/crontab. Just use an editor such as vi to edit it, and add your new line at the bottom. –  Justin Ethier May 27 '10 at 15:02
    
that is what i did, but .jar is not being executed –  Blanca May 27 '10 at 15:04
show 4 more comments

I'm going to wildly guess based on all the "it's not running!" that the job was intented to execute every hour, which is not what you wrote.

01 01 * * * root run-parts --report /home/slosada/workspace/FeedIndexer/target/FeedIndexer.sh

The minute and hour fields are both 1. That means when the current hour is 1 and the minute is 1, the job should run, which only happens at 1:01 in the morning. If you want the job to run every hour, do:

0 * * * * root run-parts --report /home/slosada/workspace/FeedIndexer/target/FeedIndexer.sh

This will run whenever the current minute is 0, which naturally happens every hour

share|improve this answer
    
no, i want to run every hour. Thank you –  Blanca May 27 '10 at 15:13
    
@Blanca I edited my answer to show how to run every hour. As I said, your current solution runs daily, not hourly, which is probably why you think it "doesn't run" -- it does, just infrequently –  Michael Mrozek May 27 '10 at 15:19
    
I tried it every minute, just for test, and the .jar is still not executing –  Blanca May 27 '10 at 15:22
    
I would guess your cron daemon isn't running then –  Michael Mrozek May 27 '10 at 15:24
    
and what could I do? –  Blanca May 27 '10 at 15:28
show 1 more comment

Your Answer

 
discard

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