# Tag Info

0

Neither of the first two conditions are met, so the else block is executed which consists of: [[ "$battery_level" -le "5" ]] # evaluates this, which does nothing notify-send ... # shows the message you are seeing Here's what you want: #!/bin/bash # Battery level warning ... 0 Just an advice and opinion; Try your script move to /usr/local/sbin or /usr/local/bin or /usr/sbin or /usr/bin or /sbin or /bin or that are known by cron(shown in PATH variable) and just add to crontab as script name. 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 ... 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. ... 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 ... 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 ... 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 ... 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 0 Cannot use apt-get --reinstall install cron because it gives back the following error: gateway:/home/firewall# apt-get --reinstall install cron Reading package lists... Done Building dependency tree... Done Suggested packages: anacron logrotate lockfile-progs checksecurity Recommended packages: exim4 postfix mail-transport-agent The following NEW ... 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. 0 I would have implemented it more like this: #!/usr/bin/python import os, shutil, subprocess filename = "backup.zip" home = "/home/nalangi" tempfile = "backupTEMP.zip" if os.path.exists(os.path.join(home, filename)): subprocess.call(["zip", "-9", "-r", tempfile, "wso2am-1.7.1"]) os.remove(os.path.join(home, filename) shutil.move(os.path.join(home, ... 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 ... 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. 0 I think your entry is awesome. It collects over the full interval vs. 1 second I see everywhere else. Because: "In the crontab entry, you should not be limiting the interval to 1 second. Sar uses the same system resources no matter how long the interval is. It reads kernel values, sleeps, reads the values again and records/prints the difference value. 1 ... 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 ... 0 Assuming there's a user that owns the news files there's likely a cron entry in this user's personal crontab entry which is responsible for this. User crons are maintained here on RHEL systems:$ sudo ls -l /var/spool/cron/ total 4 -rw-------. 1 slm slm 9 Oct 6 13:30 slm If you see entries there you can use sudo to see what's in a given file like so: \$ ...

1

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

0

watch "ps -ef | grep fetchnews" will show you the output of ps -ef | grep fetchnews every two seconds. In the output of ps -ef, the parent pid is the third field, 1458 in this case: ulmi 1462 1458 0 18:20 pts/1 00:00:00 sh -c ps -ef | grep ls That's the job that spawned your fetchnews, and it might help you on. (My crystal ball says that ...

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 ...

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

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.

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: ...

0

Checking at regular intervals is neither convenient nor reliable. If your scripts stop, they won't be restarted until the cron job runs again. There are tools for ensuring that a process is always running, such as supervise from daemontools, monit, god, supervisord, etc. Start the monitoring tool at boot time and leave it alone. while true; do … done is a ...

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 ...

0

Generally speaking, if you want to run multiple commands in a single cron task, you really should put them in a script. You shouldn't be placing double-quotes around your statement like that. It's likely to be treated as a literal. If you are truly intent on running them inline, you can do something like the following: bash -c 'whoami && which ...

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" ...

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.

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.

Top 50 recent answers are included