Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab Command Separate Line

Tags:

linux

shell

cron

I have two python scripts:

#1. getUrl.py # used to collect target urls which takes about 10 mins and used as the input for the next script #2. monitoring.py # used to monitoring the website.  00 01 * * * /usr/bin/python /ephemeral/monitoring/getUrl.py > /ephemeral/monitoring/input && /usr/bin/python /ephemeral/monitoring/monitoring.py >> /ephemeral/monitoring/output 

I put the this command in crontab and wondering how could I write that long command into two or three lines. Something like the python line separator example below but for Crontab command, so it is more readable:

>>> print \ ... 'hel\ ... llo' helllo 
like image 773
B.Mr.W. Avatar asked Sep 06 '13 15:09

B.Mr.W.


People also ask

How do I go to the next line in crontab?

You should not assume that the crontab has the same syntax as the shell script. The command field (the rest of the line) is the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab.

Can you have multiple lines in crontab?

There is no way to split a single command line onto multiple lines, like the shell's trailing "\". You can put the commands in a script and run it.

Does a crontab need a new line?

Understand your cron jobsCron requires that each entry in a crontab end in a newline character. If the last entry in a crontab is missing the newline, cron will consider the crontab (at least partially) broken and refuse to install it.

What is * * * * * In cron job?

What does * mean in Cron? The asterisk * is used as a wildcard in Cron. * sets the execution of a task to any minute, hour, day, weekday, or month.


1 Answers

No, you can't do that. From the man page:

There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

You can put the commands in a script and run it.

like image 117
Paulo Almeida Avatar answered Oct 04 '22 21:10

Paulo Almeida