Tag Info

Hot answers tagged

12

> is for redirect /dev/null is a black hole where any data sent, will be discarded 2 is the file descriptor for Standard Error > is for redirect & is the symbol for file descriptor (without it, the following 1 would be considered a filename) 1 is the file descriptor for Standard Out Therefore >/dev/null 2>&1 is redirect the output ...


6

/dev/null is a device file that acts like a blackhole. Whatever that is written to it, get discarded or disappears. When you run a script that gives you an output and if we add a > /dev/null 2>&1 at the end of the script, we are asking the script to write whatever that is generated from the script (both the output and error messages) to /dev/null. ...


4

I'd like to expand on Davidann's answer since you are new to the concept of a cron job. Every UNIX or Linux system has a crontab stored somewhere. The crontab is a plain text file. Consider the following: (From the Gentoo Wiki on Cron) #Mins Hours Days Months Day of the week 10 3 1 1 * /bin/echo "I don't really like cron" ...


4

This is standard I/O redirection. There are always three default files open. stdin (0) stdout (1) stderr (2) So in this example, the stdout (1) is being redirected to /dev/null. The null device is a device file that discards all data written to it. Then stderr is then being redirected into stdout (2>&1), therefore, both stdout and stderr will ...


3

There are at least two mistakes in your cron script: First, you should do a set -e at the beginning so that any error will end the script immediately. Moreover since you are using relative pathnames, you should do a cd to the wanted working directory: cd /home/nalangi Note. The cron(8) man page says: When executing commands, any output is mailed to ...


3

Use tee to grab the output Tee Manual tee reads from Standard INPUT/OUTPUT to write files. I have a Python script which supports one of my requirements, and simple ">" redirection fails. Tee is the way to grab output. Your line should be: 10 04 * * * user /usr/bin/python2.7 /home/user/script.py -f someFlag | tee -a ~/cronout.log 2>&1 Try this: ...


3

Yes Extra whitespace is permitted. Consider: #Mins Hours Days Months Day of the week 10 3 1 1 * /bin/echo "I don't really like cron" 30 16 * 1,2 * /bin/echo "I like cron a little" * * * 1-12/2 * /bin/echo "I really like cron" I always add column headers because I'm to lazy to ...


2

Yes extra space is allowed and you can nicely line up your fields for readability. From man 5 crontab Blank lines and leading spaces and tabs are ignored. and An environment setting is of the form, name = value where the spaces around the equal-sign (=) are optional, and any sub‐ sequent non-leading spaces in value will be part of the value ...


2

You can do : * * * * * sleep 5; script.sh * * * * * sleep 10; script.sh ... * * * * * sleep 55; script.sh to run the script every 5 seconds.


2

You need to either replace the | with && or let the script output the data to stdout and use |. When using &&, the mail command would only be run when the script exits with 0. When using the pipe character, your script needs to send the data to stdout so the pipe can pass it on to mail. In what you wrote, the script writes data to the file ...


2

By default, cron runs all jobs in the home directory of the user who owns the job. Make sure that your python script uses absolute paths when writing the output files, or it'll put them in the current user's home directory.


2

If I understand correctly, you're looking for something like this (in bash): #!/usr/bin/env bash ## avoid errors if a directory has no *tex files shopt -s nullglob directories=("Cardiology" "Rheumatology" "Surgery"); ## Change this to set whichever options you want. printf "%s\n%s\n" "\documentclass{YOURCLASS}" "\begin{document}" for directory in ...


2

It runs when the remainder of current_minute/13 is zero. So in this case it would be every 13 minutes, roughly. This means when the minutes get reset (59 to 0) it starts over. So for example */13 will always run on 0 13 26 39 52.


1

From the manual cron(8): When executing commands, any output is mailed to the owner of the crontab [...]. So what your article suggests here is to produce no output, thus sending no mail. Another way (more convenient?) to disable mail is to use the '-m off' option, i.e. crond -m off Now to the syntax: this is specific to the Bourne shell language (and ...


1

Normally when cron executes a cronjob it sends the output of the command given in the cronjob to the user account executing the cronjob. So when your cronjob executes uptime for instance the output of uptime is sent to the user by email. To be clear the standard output (stdout) of the command is meant. Now, if you execute the command uptime in the cornjob ...


1

Redirection Bash's reference manual says: The operator [n]>&word is used [...] to duplicate output file descriptors To redirect both stderr and stdout to file you should use the form &>file .... briefly: all STDERR and STDOUT messages will be redirect to /dev/null


1

That's the default behavior. crontab -e would copy the crontab file to the temporary directory, then use the editor listed in VISUAL or EDITOR environment variables to open this file, when saving, it would then try to copy the file to the original location. This is an atomic operation. The reasons behind this are varied, from preventing two users to edit ...


1

Are you absolutely sure that cron is actually running the script? What I have experienced is that in these cases if the command line is not present, mispelled....cron gets upset and never starts the command up. Which means that no output at all (nor a creation of any output files) specified in the command line. One final observation, does the PHP script ...


1

Try grep -ri fetchnews /etc/cron* /var/spool/cron/tabs/*. Are there any more results besides the line you commented out?


1

You shouldn't quote the cron job. You have */1 * * * * "whoami && which whoami" Which is looking a command literally called whoami && which whoami. Such as /usr/bin/whoami && which whoami. Obviously, this command does not exist. Remove the quotes so that the command is properly interpreted: */1 * * * * whoami && which ...


1

Instead of having a separate cron just to kick it off if it isn't running, why not just use the cron exclusively? E.g.: * * * * * 'lockfile -r 0 /tmp/the.lock; php parse_tweets.php; rm -f /tmp/the.lock' This will run the cron job which will execute parse_tweets.php once per minute using a lockfile so that you will only have one copy run by cron running ...


1

first step crontab -l > /tmp/foo second step process /tmp/foo (add entries) cat /tmp/foo /tmp/crontab.mycompany > /tmp/newcrontab finaly cat /tmp/newcrontab | crontab - to be done with either root or user. if user is not root, most likely cat /tmp/crontab.mycompany.user | crontab - as user will do.


1

Another option, which I find easier, is to run the script with cron and tell bash to login (hence using /etc/profile.d/... environment definitions) In crontab -e file: */1 * * * * bash -l -c './cron_job.sh' */1 * * * * bash -l -c 'php -f ./cron_job.php' Any command after the source of .bash_profile will have your environment as if you logged in.



Only top voted, non community-wiki answers of a minimum length are eligible