[ALUG] Setting Crons on FreeBSD

Richard Manyanza 1.liseki at gmail.com
Wed Aug 5 10:27:00 EAT 2015


Hamisi,

The ^I indicates you used a tab when editing the crontab; remove that. And
I don't know why the log file is showing "root" followed by a "space",
"tab", then command; it should just be the command. Just rewrite the line
and avoid tabs.

On Wed, Aug 5, 2015 at 9:32 AM, Hamisi Jabe via Linux <
linux at lists.habari.co.tz> wrote:

> Dear Adreas,
>
>
> I was running this as a global cron added on the* /etc/crontab*    file
>
> */10    *       *       *       *       root    /usr/local/bin/bash
> /etc/rsync.sh
>
>
>
>
> *The Script file content  rsync.sh*
> __________________________________________________________________________________________________
>
> #!/usr/local/bin/bash
> rsync -v --archive --delete root at x.x.x.x:/srv/vmail/banana.co.tz/
> /home/virtual/banana.co.tz/
> cd  /home/
> chown -R vscan:vscan virtual
>
> ___________________________________________________________________________________________________
>
>
> When i tail the  /var/log/cron file i get the results below
>
> tail -f /var/log/cron
> Aug  5 12:00:00 mx3 /usr/sbin/cron[17249]: (root) CMD (
> /usr/libexec/atrun)
> Aug  5 12:00:00 mx3 /usr/sbin/cron[17248]: (root) CMD (   newsyslog)
> *Aug  5 12:00:00 mx3 /usr/sbin/cron[17250]: (root) CMD (root
> ^I/usr/local/bin/bash  /etc/rsync.sh)*
> Aug  5 12:01:00 mx3 /usr/sbin/cron[17283]: (*system*) RELOAD (/etc/crontab)
> Aug  5 12:05:00 mx3 /usr/sbin/cron[17435]: (root) CMD (
> /usr/libexec/atrun)
> Aug  5 12:10:00 mx3 /usr/sbin/cron[17508]: (root) CMD (
> /usr/libexec/atrun)
> *Aug  5 12:10:00 mx3 /usr/sbin/cron[17507]: (root) CMD
> (^I/usr/local/bin/bash /etc/rsync.sh)*
> *Aug  5 12:10:00 mx3 /usr/sbin/cron[17509]: (root) CMD (root
> ^I/usr/local/bin/bash  /etc/rsync.sh)*
> Aug  5 12:11:00 mx3 /usr/sbin/cron[17622]: (operator) CMD
> (/usr/libexec/save-entropy)
> Aug  5 12:15:00 mx3 /usr/sbin/cron[17699]: (root) CMD (
> /usr/libexec/atrun)
>
>
>
> May be you can check the results above if its the script problem or,
> because if i run the command using:-
>
> *bash /etc/rsync.sh *
> *sh /etc/rsync.sh*
> * /usr/local/bin/bash  /etc/rsync.sh*
>
>
> It is running successfully from start to end
>
>
> Thanks
>
>
>
>
>
>
>
>
>
> On 04/08/2015 09:05 alasiri, Richard Manyanza via Linux wrote:
>
> Hamisi, adding to your confusion (and hopefully clarity):
>
> Are you using the root crontab or a normal user's crontab?
>
> Your script is in /etc; does it need root access to run? If so you have to
> put your cron entry in the root crontab (/etc/crontab). The format of this
> crontab, unlike a normal user's crontab, includes a user parameter before
> the command and should read:
>
> */30 * * * * root /usr/local/bin/bash /etc/rsync.sh
>
>
> On Tue, Aug 4, 2015 at 7:09 PM, Andreas Tauscher via Linux <
> linux at lists.habari.co.tz> wrote:
>
>> On 08/04/2015 04:51 PM, Hamisi Jabe via Linux wrote:
>> > Dear All,
>> >
>> > Hope everyone is doing on fine,
>> >
>> > I am trying to set crons on Freebsd to run a script but its not
>> > executing though when i run the script directly it is running properlly
>> > from start to end
>> >
>> > Please help
>> >
>> > script directory   without the quotes        "*/etc/rsync.sh*"
>> >
>> > cron job command   without the quotes    "*/*30 * * * *
>> > /usr/local/bin/bash /etc/rsync.sh*"
>>
>> The /etc/contab format is slightly different from the user contab
>> There are two manpages for crontab.
>> You might have checked "man crontab" which gives you the man page for
>> user crontabs from section 1 "executable programs or shell commands"
>> (first match) and "man 5 crontab" is the manpage for the systemwide
>> crontab from section 5 "file formats and conventions" you wanted.
>>
>> There is an important information missing in this line:
>> The username the script will be executed as which is not requires in
>> user crontabs.
>> You tell cron run /etc/rsync.sh as user /usr/local/bin/bash
>> In the system log you find surely:
>> "cron: Error: bad username; while reading /etc/crontab"
>> The */*30 is also wrong this will give an
>> "cron: (*system*) ERROR Syntax error"
>> *system* indicates here the system wide crontab. If the error is in a
>> user crontab then there is the username logged.
>> Any error making the entire crontab to be ignored.
>>
>> To run the script every 30 minutes you write */30 * * * *
>>
>> When your crontab looks like this:
>> ---- SNIP -----
>> SHELL=/bin/sh
>> PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
>>
>> */30 * * * *  <username> /etc/rsync.sh
>> ----- SNAPP -----
>> And your script is starting with a shebang (#!/usr/local/bin/bash) the
>> scrip will run every 30 minutes.
>>
>> Andreas
>>
>>
>> _______________________________________________
>> The Arusha Linux User Group: http://unix.or.tz
>> Linux mailing list
>> Linux at lists.habari.co.tz
>> http://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux
>>
>> The Arusha LUG mailing list is generously hosted by Habari Node Ltd:
>> http://www.habari.co.tz/
>>
>> The above comments and data are owned by whoever posted them (including
>> attachments if any). The mailing list host is not responsible for them in
>> any way.
>>
>
>
>
> _______________________________________________
> The Arusha Linux User Group: http://unix.or.tz
> Linux mailing listLinux at lists.habari.co.tzhttp://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux
>
> The Arusha LUG mailing list is generously hosted by Habari Node Ltd: http://www.habari.co.tz/
>
> The above comments and data are owned by whoever posted them (including attachments if any). The mailing list host is not responsible for them in any way.
>
>
>
> _______________________________________________
> The Arusha Linux User Group: http://unix.or.tz
> Linux mailing list
> Linux at lists.habari.co.tz
> http://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux
>
> The Arusha LUG mailing list is generously hosted by Habari Node Ltd:
> http://www.habari.co.tz/
>
> The above comments and data are owned by whoever posted them (including
> attachments if any). The mailing list host is not responsible for them in
> any way.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.habari.co.tz/pipermail/linux/attachments/20150805/0f93475b/attachment.html>


More information about the Linux mailing list