Results 1 to 5 of 5

Thread: Strange behaviour: CRON requires having logged in to do sudo commands

  1. #1
    Join Date
    May 2009
    Beans
    266

    Strange behaviour: CRON doesn't do all your crontab jobs until you log in once

    This is sort of a ramification of my previous thread:

    Can sudoers sudo in their crontabs? - How?

    (edit): But it points out other problems I'm facing using crontabs with sudo commands.


    (A)
    As soon as the system boots, CRON starts executing the jobs that users have in their crontabs at their due time, even if the users have not yet logged in EXCEPT those that include a sudo-command and the user can execute without the need of password identification.

    The moment the user loggs in (and even out) CRON is able to execute the jobs that include sudo commands too.


    Code:
    cat /home/user/cron/CRON.LOG
    16 Jul 23:35:03 ntpdate[20020]: adjust time server 91.189.94.4 offset -0.013027 sec
    Thu Jul 16 23:35:03 CEST 2009 - ~/cron/ntpdate.sh
    17 Jul 00:35:03 ntpdate[21011]: adjust time server 62.93.230.13 offset -0.007102 sec
    Fri Jul 17 00:35:03 CEST 2009 - ~/cron/ntpdate.sh
              <---- System Shutdown ---->
    
             <---- System Reboot   ---->
    (CRON is not doing all commands in user's crontab s cript:)
    Fri Jul 17 11:35:01 CEST 2009 - ~/cron/ntpdate.sh
    Fri Jul 17 12:35:01 CEST 2009 - ~/cron/ntpdate.sh
    Fri Jul 17 13:35:01 CEST 2009 - ~/cron/ntpdate.sh
    
              <---- user, owner of the crontab, logged in AND OUT at 14:30 ---->
    (CRON starts doing ALL commands in user's crontab script, including sudo commands:)
    17 Jul 14:35:02 ntpdate[8503]: adjust time server 192.33.96.102 offset 0.079122 sec
    Fri Jul 17 14:35:02 CEST 2009 - ~/cron/ntpdate.sh
    As you can see, one part of the job in the crontab is not being done even if it is in the same script.


    Is this how it should be?
    I don't see any reason why.
    Is there any way to avoid this?

    According to what I have been observing around a user can never be sure if his jobs are going to be done or not until he has done all kinds of unimaginable tests.
    ------

    (B)
    A script whose filename includes a dot (file.name) placed in /etc/cron.hourly is not being done.
    The same script with an underscore (file_name) in the name is done perfectly.

    Is this normal?
    Last edited by HotForLinux; July 17th, 2009 at 11:10 PM. Reason: changed title

  2. #2
    Join Date
    Jun 2007
    Location
    Oklahoma City, OK
    Beans
    200
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Strange behaviour: CRON requires having logged in to do sudo commands

    If you don't already have it, you probably need a nopasswd line in your /etc/sudoers for ntpdate.
    Te audire no possum. Musa sapientum fixa est in aure.

  3. #3
    Join Date
    May 2009
    Beans
    266

    Re: Re: Strange behaviour: CRON doesn't do all your crontab jobs until you log in

    Thanks but I'm talking about a completely different thing here.

    (In the previous thread that I mentioned above I talked about that issue. Not only the line you say is needed in the sudoers file, but attention should be paid to the position it occupies in that file)
    Last edited by HotForLinux; July 17th, 2009 at 11:04 PM.

  4. #4
    Join Date
    Jun 2007
    Location
    Oklahoma City, OK
    Beans
    200
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Strange behaviour: CRON doesn't do all your crontab jobs until you log in

    Quote Originally Posted by HotForLinux View Post
    Thanks but I'm talking about a completely different thing here.

    (In the previous thread that I mentioned above I talked about that issue. Not only the line you say is needed in the sudoers file, but attention should be paid to the position it occupies in that file)
    If I have time I'll play around with it. Probably end up stracing the cron jobs while I'm logged in and logged out.

    I just put in a nopasswd line today after the %admin line and it worked just fine with nopasswd, didn't prompt. So we'll see.
    Te audire no possum. Musa sapientum fixa est in aure.

  5. #5
    Join Date
    May 2009
    Beans
    266

    Re: Strange behaviour: CRON doesn't do all your crontab jobs until you log in

    The problem is not that cron doesn't do your sudo commands in your crontab scripts when you are logged out but that it doesn't do them BEFORE YOU LOG IN for the first time after a reboot.
    Last edited by HotForLinux; July 18th, 2009 at 06:33 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •