0

In my current directory, I have a bash script called run_job.sh. This script runs perfectly fine.

I'm trying to schedule this script to run every 10 minutes using a cronjob. Here is the code that I am using:

*/10 * * * * run_job.sh 

Now, when I do this, I get the following error:

-bash: */10: No such file or directory when running

I'm new to cron jobs so I'm not sure why I'm getting this error. Any help would be much appreciated.

madsthaks
  • 377
  • 1
  • 6
  • 16
  • 1
    This is not a valid Bash script. You probably want to provide it as input to `crontab` instead. – tripleee Jan 24 '20 at 19:15
  • @tripleee can you please elaborate on this? This is my first time using a cron job – madsthaks Jan 24 '20 at 19:18
  • You're not revealing how you are trying to run this, but the error message looks like you did something like `bash file`. This attempts to run `file` as a Bash script, which it is not. Try `crontab – tripleee Jan 24 '20 at 19:19
  • Or maybe you just typed that at the bash prompt; run `crontab -e` and type it into your editor instead. (If you end up in a hostile `vi`, type `i` to insert something, and esc `:` `w` `q` to save it and quit.) – tripleee Jan 24 '20 at 19:22
  • So, my bash script runs a few python scripts. Looking at some resources online, I noticed they run the command I included to schedule a job. Are you suggesting I include it within `crontab -e` then run `crontab run_job.sh` in the terminal? – madsthaks Jan 24 '20 at 19:26
  • No, the use of `crontab` is to update your `cron` settings. It's really unclear which part of this you are having trouble with but developing new wild ideas down here in the comments seems like a step in the wrong direction. Maybe look for a simple "hello world" cron tutorial and come back when you have done that successfully. – tripleee Jan 24 '20 at 19:29

2 Answers2

2

The error message in your question suggests that you passed the crontab snippet to Bash somehow. That's not how you schedule a job; you type the command crontab -e at the Bash prompt and edit your Cron schedule in your favorite editor. That's where you would type in this snippet. When you save the file and exit the editor, cron will take your new schedule into use.

However, you should be aware that your normal PATH and other features of your interactive environment will not be available to cron jobs. At a minimum, you will probably need to specify the path to your script. If it's in $HOME/bin/run_job.sh, that's what you need to put in the final field in the crontab entry. (There may be more tweaks you have to do which can't be inferred from the information you have provided; see e.g. CronJob not running for further tips.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

What you are showing is the scheduling line from crontab (see man crontab). Further, I recommend against the /10 format, as it is not accepted by cron on all operating systems. To be safe, it is better to be explicit, as in:

0,10,20,30,40,50 * * * * run_job.sh 
RandomW
  • 11
  • 3
  • 1
    I've rarely if ever had a requirement for a crontab to be portable to systems that don't support the `/10` syntax. – Keith Thompson Jan 24 '20 at 19:34
  • Some of us manage multiple different operating systems, including Solaris. It's still a valid reason. – RandomW Jan 24 '20 at 19:51
  • But it's not at all an answer to the question at the top of this page. Once you earn enough reputation points, you will be able to leave comments; until then, probably focus on askrng and answering questions. – tripleee Jan 24 '20 at 20:13