Re: Cron Question
Can anyone help me with this? Thank you again. -- View this message in context: http://www.nabble.com/Cron-Question-tp19272656p19343758.html Sent from the freebsd-questions mailing list archive at Nabble.com. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron Question
Thank you for the help. I changed the script to run Weekly instead of Daily. If it was starting while it was still running, this should fix it. I'll post my progress, and thank you again. -- View this message in context: http://www.nabble.com/Cron-Question-tp19272656p19287970.html Sent from the freebsd-questions mailing list archive at Nabble.com. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron Question
At 10:45 AM 9/2/2008, ElihuJ wrote: Hi all. I have a question about cron jobs that seem to be running to long or with multiple copies of itself. For example, I have a backup script that I run that seems to make multiple copies of itself. If I view the running processes I see numerous instances of the same cron job. Is there something I can do to limit this from happening? When it does, it drains my CPU and some of my other processes are non responsive. Any help would be appreciated. Thank you. -- View this message in context: http://www.nabble.com/Cron-Question-tp19272656p19272656.html Sent from the freebsd-questions mailing list archive at Nabble.com. For longer running jobs I do a couple things. I use a file to be sure only one instance is running, but I also add signal handling. The following is written for ksh, but can be adapted to sh if needed: = #!/usr/local/bin/ksh # uncomment the following line for debugging #set -x RUNNING_FILE=RUNNING_FILE=/tmp/my_cronjob_running LOGFILE=LOGFILE=/tmp/my_cronjob.log [EMAIL PROTECTED] MAIL=/usr/bin/mail TOUCH=/usr/bin/touch RM=/bin/rm # Print an epilog string and clear the RUNNING_FILE function epilog { echo "We are all done scanning." >> $LOGFILE $MAIL -s "MyCronjob Report" $SENDTO < $LOGFILE if [ -f $RUNNING_FILE ]; then $RM $RUNNING_FILE; fi } function got_signal { echo "Got a signal" >> $LOGFILE epilog exit } # Here pointers to signal handling subroutines are set trap got_signal TERM HUP INT QUIT if [ -f $RUNNING_FILE ]; then echo "mycronjob is already running" else $TOUCH $RUNNING_FILE $RM $LOGFILE $TOUCH $LOGFILE # add your job to be done here . . . # epilog fi = ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron Question
On Tue, 2 Sep 2008 11:40:37 -0500 Dan Nelson <[EMAIL PROTECTED]> wrote: > I use the lockfile command ( from the procmail port ) to ensure that > recurring cron jobs don't overlap if one run takes too long. For > example, to run mrtg on a 1-minute cycle but prevent multiple mrtgs > from running if one run takes longer than 1 minute: > > * * * * * /usr/local/bin/lockfile -r 1 -l 3600 /tmp/mrtg.LCK && > ( nice -19 /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg ; > rm /tmp/mrtg.LCK ) > > The -l 3600 tells lockfile to remove any lockfiles over an hour old ( > if the machine was rebooted during an mrtg run for example ) > you could also handle stale lock-files, without installing procmail, like this: LCK=/tmp/foo.LCK find $LCK -mtime +3600s -delete if ![ -f "$LCK" ] ; then touch "$LCK" [ -f "$LCK" ] && foo rm "$LCK" fi Presumably the lockfile command also eliminates the race between testing for, and creating, the lock-file, but that's not really needed here. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron Question
In the last episode (Sep 02), Paul Schmehl said: > --On September 2, 2008 6:03:51 PM +0200 Albert Shih wrote: > > Le 02/09/2008 à 08:45:52-0700, ElihuJ a écrit > >> Hi all. I have a question about cron jobs that seem to be running > >> to long or with multiple copies of itself. For example, I have a > >> backup script that I run that seems to make multiple copies of > >> itself. If I view the running processes I see numerous instances > >> of the same cron job. Is there something I can do to limit this > >> from happening? When it does, it drains my CPU and some of my > >> other processes are non responsive. Any help would be appreciated. > >> Thank you. > > > > That's not the to cron to do that. > > Actually, it could be. If the script is started by cron and is still > running when the next job is scheduled, cron will start another > process. If they're both still running when the next job is > scheduled, you'll have three processes running, etc., etc. I use the lockfile command ( from the procmail port ) to ensure that recurring cron jobs don't overlap if one run takes too long. For example, to run mrtg on a 1-minute cycle but prevent multiple mrtgs from running if one run takes longer than 1 minute: * * * * * /usr/local/bin/lockfile -r 1 -l 3600 /tmp/mrtg.LCK && ( nice -19 /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg ; rm /tmp/mrtg.LCK ) The -l 3600 tells lockfile to remove any lockfiles over an hour old ( if the machine was rebooted during an mrtg run for example ) -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron Question
--On September 2, 2008 6:03:51 PM +0200 Albert Shih <[EMAIL PROTECTED]> wrote: Le 02/09/2008 à 08:45:52-0700, ElihuJ a écrit Hi all. I have a question about cron jobs that seem to be running to long or with multiple copies of itself. For example, I have a backup script that I run that seems to make multiple copies of itself. If I view the running processes I see numerous instances of the same cron job. Is there something I can do to limit this from happening? When it does, it drains my CPU and some of my other processes are non responsive. Any help would be appreciated. Thank you. That's not the to cron to do that. Actually, it could be. If the script is started by cron and is still running when the next job is scheduled, cron will start another process. If they're both still running when the next job is scheduled, you'll have three processes running, etc., etc. The first thing I would do is run the script manually and see how long it takes to complete. Then set your cron jobs up to run with enough time between them for the script to complete and exit before the next job starts. Paul Schmehl, If it isn't already obvious, my opinions are my own and not those of my employer. ** WARNING: Check the headers before replying
Re: Cron Question
Le 02/09/2008 à 08:45:52-0700, ElihuJ a écrit > > Hi all. I have a question about cron jobs that seem to be running to long or > with multiple copies of itself. For example, I have a backup script that I > run that seems to make multiple copies of itself. If I view the running > processes I see numerous instances of the same cron job. Is there something > I can do to limit this from happening? When it does, it drains my CPU and > some of my other processes are non responsive. Any help would be > appreciated. Thank you. That's not the to cron to do that. You must put in your script some flags. For example if you using rsnapshot (in the ports) he put a lock file in /var/run (or what's ever you want) and don't start if the script find this file. When the script is end the file is erase. Something like if_the_lock_file_exit : exit 1 else touch lock_file my_script rm lock_file fi. Regards -- Albert SHIH SIO batiment 15 Observatoire de Paris Meudon 5 Place Jules Janssen 92195 Meudon Cedex Heure local/Local time: Mar 2 sep 2008 18:01:25 CEST ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron question
On Apr 25, 2008, at 10:31 AM, John Almberg wrote: ...and invoking this wrapper from cron instead of trying to reset the shell and everything from within cron. You can test things by doing an "su gs -c /bin/sh" from a root login and then trying to run your wrapper, which will give you a minimum environment closer to what cron executes under. This was an interesting idea. I wrote a little ruby script to print out all set environment variable, then ran it under the simulated cron environment: bin 520 $ su gs -c /bin/sh $ ./env.rb USER => gs MAIL => /var/mail/gs SHLVL => 2 HOME => /home/gs _ => /bin/sh BLOCKSIZE => K TERM => xterm-color SVN_EDITOR => vim PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/ usr/local/bin:/usr/X11R6/bin:/home/gs/bin SHELL => /usr/local/bin/bash PWD => /home/gs/bin FTP_PASSIVE_MODE => YES EDITOR => vim $ Then under the environment I used to run the script by hand: [EMAIL PROTECTED] ~/bin]$ ./env.rb TERM => xterm-color SHELL => /usr/local/bin/bash OLDPWD => /home/gs SSH_TTY => /dev/ttyp0 USER => gs SVN_EDITOR => vim FTP_PASSIVE_MODE => YES MAIL => /var/mail/identry PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/ usr/local/bin:/usr/X11R6/bin:/home/identry/bin BLOCKSIZE => K PWD => /home/gs/bin EDITOR => vim HOME => /home/gs SHLVL => 2 LOGNAME => identry _ => ./env.rb I don't see any difference that would explain this problem... No mail is sent to either root or gs when the crontab runs. Well, I finally figure this out. Printing out the environment variables when running the program by hand, and then when it ran as a crontab, turned out to be the key. The difference (not shown in the early experiment, above) was in the working directory. When I ran the script by hand, the working directory was /home/gs/bin, but when cron ran the script, the working directory was /home/gs. Unfortunately, this caused the script to die, because of a bug in the script itself. Now that this script is running, the big question is, why are none of my login users getting any email? I'm sure that cron tried to send an email about the error that would have been helpful in debugging the problem, but it never arrived. But all the mailboxes in /var/mail are empty. I am running qmail, which is also new for me... Like all djb stuff, it works great, but is stunningly difficult for my feeble brain to understand... I need to roll up my sleeves and try to understand what's happening to this mail. Anyway, thanks for the help. It was definitely useful in putting me on the right track. Brgds: John ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron question
...and invoking this wrapper from cron instead of trying to reset the shell and everything from within cron. You can test things by doing an "su gs -c /bin/sh" from a root login and then trying to run your wrapper, which will give you a minimum environment closer to what cron executes under. This was an interesting idea. I wrote a little ruby script to print out all set environment variable, then ran it under the simulated cron environment: bin 520 $ su gs -c /bin/sh $ ./env.rb USER => gs MAIL => /var/mail/gs SHLVL => 2 HOME => /home/gs _ => /bin/sh BLOCKSIZE => K TERM => xterm-color SVN_EDITOR => vim PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/ local/bin:/usr/X11R6/bin:/home/gs/bin SHELL => /usr/local/bin/bash PWD => /home/gs/bin FTP_PASSIVE_MODE => YES EDITOR => vim $ Then under the environment I used to run the script by hand: [EMAIL PROTECTED] ~/bin]$ ./env.rb TERM => xterm-color SHELL => /usr/local/bin/bash OLDPWD => /home/gs SSH_TTY => /dev/ttyp0 USER => gs SVN_EDITOR => vim FTP_PASSIVE_MODE => YES MAIL => /var/mail/identry PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/ local/bin:/usr/X11R6/bin:/home/identry/bin BLOCKSIZE => K PWD => /home/gs/bin EDITOR => vim HOME => /home/gs SHLVL => 2 LOGNAME => identry _ => ./env.rb I don't see any difference that would explain this problem... No mail is sent to either root or gs when the crontab runs. Someone asked what version of PHP... ~ 504 $ php --version PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 6 2008 18:26:54) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies ~ 505 $ And if bash is really installed: ~ 505 $ bash --version GNU bash, version 3.2.33(0)-release (amd64-portbld-freebsd6.3) Copyright (C) 2007 Free Software Foundation, Inc. I guess I will try using the shell script wrapper idea, to some more experiments in a more controlled environment. -- John ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron question
On Thu, Apr 24, 2008 at 3:26 PM, John Almberg <[EMAIL PROTECTED]> wrote: > SHELL=/usr/local/bin/bash Did you install bash from ports and does it run OK from outside of cron? > > PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/home/gs/bin > HOME=/home/gs > 0 15 * * * /home/gs/bin/script.php >>/home/gs/log/script.log > > I can see from the cron log that cron runs script.php at the appointed > hour: > > Apr 24 15:00:03 on /usr/sbin/cron[72414]: (gs) CMD > (/home/gs/bin/script.php >>/home/gs/log/script.log) This entry in the cron log will still show up if the shell listed in the crontab is not available. However, as someone else already mentioned, cron sends a mail when it goes to run and can't execute the shell. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron question
0 15 * * * /usr/local/bin/php /home/gs/bin/script.php /home/gs/log/script.log looks right. check mail - cron sends mail if something is wrong ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Cron question
On Apr 24, 2008, at 1:26 PM, John Almberg wrote: The trouble comes when I try to run this script with cron. I have something like this in the gs user crontab: SHELL=/usr/local/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/ local/bin:/usr/X11R6/bin:/home/gs/bin HOME=/home/gs 0 15 * * * /home/gs/bin/script.php >>/home/gs/log/script.log I can see from the cron log that cron runs script.php at the appointed hour: Apr 24 15:00:03 on /usr/sbin/cron[72414]: (gs) CMD (/home/gs/bin/ script.php >>/home/gs/log/script.log) I believe that you are going to be better off writing a trivial wrapper like: - #! /usr/local/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/ local/bin:/usr/X11R6/bin:/home/gs/bin # ...other env variables you need... touch /home/gs/log/script.log /home/gs/bin/script.php >> /home/gs/log/script.log - ...and invoking this wrapper from cron instead of trying to reset the shell and everything from within cron. You can test things by doing an "su gs -c /bin/sh" from a root login and then trying to run your wrapper, which will give you a minimum environment closer to what cron executes under. -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
On Wednesday 05 April 2006 01:32, Kevin Kinsey wrote: > And furthermore, you edited /etc/crontab or something similar > instead of using crontab(1) to edit /var/cron/tabs/root. Nitpicky, > to be sure, but the cause of many a heartache: > > http://www.freebsd.org/doc/en/books/faq/admin.html#ROOT-NOT-FOUND-CRON-ERRO >RS The FAQ entry is about the mistake of using the crontab utility to install the system crontab (or a copy) as root's user crontab ( This is not helped by the fact that /etc/crontab refers to itself as "root's crontab" ). There is no such problem with simply editing /etc/crontab - it's the more straightforward approach. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
On 2006-04-05 07:03, Marlon Martin <[EMAIL PROTECTED]> wrote: > i created a simple shell script: > > filename: rn > > #!/bin/sh > rndc dumpdb > > what it does, is just dump the hostname and IP addresses in /var/dump > i set the time in 2 minutes but when i checked the logs, it doesnt work any > idea what did i missed here? > > == > > SHELL=/bin/sh > PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin > HOME=/var/log > # > #minute hourmdaymonth wdaywho command > # > */5 * * * * root/usr/libexec/atrun > # > # Save some entropy so that /dev/random can re-seed on boot. > */11 * * * * operator /usr/libexec/save-entropy > # > # Rotate log files every hour, if necessary. > 0 * * * * rootnewsyslog > # > # Perform daily/weekly/monthly maintenance. > 1 3 * * * rootperiodic daily > 154 * * 6 rootperiodic weekly > 305 1 * * rootperiodic monthly > /2 * * * * root /home/ken/rn You are missing a star '*' character before '/2' near the beginning of the line immediatelly above. Try this instead: */2 * * * * root /home/ken/rn Then make sure /home/ken/rn is executable. I'd also suggest moving your `rn' script in `/root/scripts/rn' and making `root:wheel' its owner. The crontab entries from `/etc/crontab' are executed with root permissions, so giving the user `ken' control over what runs is creating a backdoor for anyone who gets access to that non-root user account. - Giorgos ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
Chuck Swiger wrote: Marlon Martin wrote: i created a simple shell script: filename: rn #!/bin/sh rndc dumpdb what it does, is just dump the hostname and IP addresses in /var/dump i set the time in 2 minutes but when i checked the logs, it doesnt work any idea what did i missed here? You forgot to use the full path to rndc in your shell script. You should not assume that the $PATH cron passes you is going to have that command available. And furthermore, you edited /etc/crontab or something similar instead of using crontab(1) to edit /var/cron/tabs/root. Nitpicky, to be sure, but the cause of many a heartache: http://www.freebsd.org/doc/en/books/faq/admin.html#ROOT-NOT-FOUND-CRON-ERRORS ... not sure if this one's affected you or not, but I'm wondering Kevin Kinsey -- Acid absorbs 47 times its own weight in excess Reality. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
Marlon Martin wrote: > i created a simple shell script: > > filename: rn > > #!/bin/sh > rndc dumpdb > > what it does, is just dump the hostname and IP addresses in /var/dump > i set the time in 2 minutes but when i checked the logs, it doesnt work any > idea what did i missed here? You forgot to use the full path to rndc in your shell script. You should not assume that the $PATH cron passes you is going to have that command available. -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
Jim Pazarena <[EMAIL PROTECTED]> writes: > I am trying to grep for a record from a crob job... > the entry looks like this: > 58 23 * * * grep `date "+%Y-%m-%d "` /log/fylename | mail admin > > cron complains: > Syntax error: EOF in backquote substitution > > could someone enlighten me please? You've got a quoting nightmare there. Try wrapping it up in a shell script to be called from cron, and you won't have to worry what cron does to the tokens. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: cron question
On 2003-03-14 16:08, Kenzo <[EMAIL PROTECTED]> wrote: > I'm trying to automatically create a report in cron and E-mailling it to my > E-mail account. > > this is what I have. > > 0 1 0 0 0 root /usr/bin/perl /usr/local/bin/spamstat.pl /var/log/maillog.0 > > /var/log/spam_report | uuencode spam_report spam_report | mail -s > "spam_daily_report" [EMAIL PROTECTED] What is 0 1 0 0 0 supposed to do? I am inclined to think you have the time information on that crontab line all wrong. You're redirecting all output from spamstat.pl to the file /var/log/spam_report. Nothing goes down the pipe to uuencode. > what I get is a blanc attachment. > the spam_report file does get created in the /var/log dir with all the right > stuff in it, so I don't get why it won't E-mail it. > I have the same setup for another report and it works fine. > > I know this would probably work better if I created a script to do all this > and have cron run the script, but I don't know how to write any scripts. Just put the commands in /root/spam_report.sh and chmod 755 it.A Try this script: #!/bin/sh /usr/bin/perl /usr/local/bin/spamstat.pl /var/log/maillog.0 | \ uuencode spam_report | \ mail -s "spam_daily_report" [EMAIL PROTECTED] Then you can make this executable with: # chmod u+x /root/spam_report.sh and call it from /etc/crontab as: 0 1 * * * root /root/spam_report.sh That should work fine :) - Giorgos To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-questions" in the body of the message