Shell Crontab and Logging

Dear All my BSD profesional friends
I was looking for some solutions to do some jobs via my server for my application.
so i found crontab cloud handle that.

i want to code this idea:

every hour set date: "ntpdate -v -b in.pool.ntp.org" and write a log to my date.log that server has updated and can view whole update report
then
backup my sqlevery night at 12 mysqldump datebase > /usr/backup/dateDATE/database.Date.sql


here is my crontab Configure:

Code:
59 * * * * ntpdate -v -b in.pool.ntp.org
59 12 * * * mysqldump -u root -p PASSWORD database >  database.Date.sql

the point is it does not work even i tried:
Code:
* * * * * echo hello

I really need this
I don't know I checked service cron status its running but not working as well
 
Last edited by a moderator:
* * * * * echo hello
Well that wont work because you did not tell it how often to run.
Here is a crontab I use:
Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
# Order of crontab fields
# minute        hour    mday    month   wday    command
*/1             *       *       *       *       /usr/local/bin/cpu_mon.app
This runs a command every minute. To ensure that the cron job is working I look here:
tail /var/log/cron
 
Last edited by a moderator:
Please try to include the full path of the commands and files. The first line should be ok because /usr/sbin should be in the default path of crontab(5). The echo should work if you specify a mail account in the first line where to report to. I have never tried that without MAILTO. Please see crontab(5) for examples.
 
Tell me this:
Every 59Min Do this:
crontab -e
Code:
59 * * * * ntpdate -v -b in.pool.ntp.org
[esp]:wq
Code:
59 * * * * ntpdate -v -b in.pool.ntp.org
it does not work
 
Last edited by a moderator:
Look is there any configuration I should do?
Maybe I should edit /etc/crontab.conf?
 
Last edited by a moderator:
No crontab -e[PORT][/PORT] reloads the rules for you. Use only it.

With whitespace in your command the first thing I would experiment with is various quotes "" and '' around the command.

Also like above you are running "echo hello" but outputting it where?
This is a system script facility that runs in the backround. You will see no text on the console unless you make it so.
 
well I just added this line and it works fine:
*/1 * * * * ntpdate -v -b pool.ntp.org

Code:
root@E6420:~ # tail /var/log/cron
Dec 26 02:35:00 E6420 /usr/sbin/cron[6135]: (root) CMD (/usr/libexec/atrun)
Dec 26 02:36:08 E6420 crontab[6478]: (root) BEGIN EDIT (root)
Dec 26 02:37:39 E6420 crontab[6478]: (root) REPLACE (root)
Dec 26 02:37:40 E6420 crontab[6478]: (root) END EDIT (root)
Dec 26 02:38:00 E6420 /usr/sbin/cron[7041]: (root) CMD (ntpdate -v -b pool.ntp.org)
Dec 26 02:38:51 E6420 crontab[7274]: (root) BEGIN EDIT (root)
Dec 26 02:39:06 E6420 /usr/sbin/cron[7389]: (root) CMD (ntpdate -v -b pool.ntp.org)
Dec 26 02:40:00 E6420 /usr/sbin/cron[7617]: (root) CMD (/usr/libexec/atrun)
Dec 26 02:40:00 E6420 /usr/sbin/cron[7618]: (root) CMD (ntpdate -v -b pool.ntp.org)
 
Dear saeedpersa,
I have just tried your command in the crontab as root and it works, of course with 7 minutes instead of 59 minutes. May be the issue is that ntpdate must be run using the root account. Have you confirmed if ntpdate works when launched from a shell?
 
Now, I know this doesn't dive into the crontab issues (seriously though: the manualpages for crontab(5) and cron(8) explain all which has been explained above), however I can't help wonder why you'd want to run ntpdate all the time?

Why not use ntpd instead and let it worry about keeping your time fully synchronized?

See /etc/ntp.conf as well as ntpd(8) for more information. All you'd have to do is enable the daemon in /etc/rc.conf and you're all set. I can't help think that this will be a lot more smoother than forcefully (re)setting the time and date every hour or so.
 
Why not use ntpd instead and let it worry about keeping your time fully synchronized?

See /etc/ntp.conf as well as ntpd(8) for more information. All you'd have to do is enable the daemon in /etc/rc.conf and you're all set. I can't help think that this will be a lot more smoother than forcefully (re)setting the time and date every hour or so.

I use this in my /etc/rc.conf:

Code:
ntpd_enable="YES"
ntpd_sync_on_start="YES"
 
Back
Top