cron, python and samba restart

Discussion in 'Python' started by symbioid, Oct 27, 2007.

  1. symbioid

    symbioid Guest

    Hello,

    I'm working on a project, and VMware has problems with suspending the
    virtual machine. We are accessing the machine through samba.
    However, when I suspend the VM, it stops the Samba service.

    The solution we hit upon was to run a script that checks, say, once a
    minute to determine whether the machine was active or suspended. If
    it's been longer than a minute, we restart the samba service.

    I have been able to manually execute the script, and it properly
    restarts the service. When running from cron, however, the service
    won't restart. I am able to write the file out, so I know it's
    running the script.

    Is there something in the way I'm calling with the subprocess.call()
    function that's not able to work through cron? My concern is that I'm
    using sudo, and that may be where the problem lies. I've had the
    process run as both root and as localuser in the crontab, both with
    and without "sudo"ing the command. None works. I don't know how cron
    would run a sudo command in this case, anyways...

    Any hints would be appreciated.


    ----------

    #!/usr/bin/python
    import os.path
    import time
    import subprocess

    t = str(int(time.time()))
    f = "gasr.dat"

    if os.path.exists(f):
    file = open(f,'r')
    timestamp = file.readline()
    file.close()

    cur_time = int(time.time())
    difference_in_mins = (cur_time - int(timestamp))/60
    if difference_in_mins > 1:
    subprocess.call('sudo /etc/init.d/samba restart', shell=True)
    file = open(f,'w')
    file.write(t)
    file.close()
    symbioid, Oct 27, 2007
    #1
    1. Advertising

  2. symbioid <> wrote:
    > Is there something in the way I'm calling with the subprocess.call()
    > function that's not able to work through cron? My concern is that I'm
    > using sudo, and that may be where the problem lies.


    http://www.gratisoft.us/pipermail/sudo-users/2005-May/002518.html

    Todd C. Miller Todd.Miller at courtesan.com wrote:
    > Your sudo is configured to only run when there is a tty
    > present, whcih is not the case for cron jobs. Usually this
    > is due to a line like the following in sudoers:
    >
    > Defaults requiretty
    >
    > Removing this (or just disabling it for the user who must run the
    > cron job) should eliminate the error. Note that you will also need
    > to disable authentication either via the NOPASSWD tag or the
    > "authenticate" Defaults option.


    Check the PATH in cron also

    --
    Nick Craig-Wood <> -- http://www.craig-wood.com/nick
    Nick Craig-Wood, Oct 29, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob@Bedford
    Replies:
    4
    Views:
    7,116
    brunasti
    Dec 6, 2007
  2. Josef Dalcolmo

    computer names and samba shares

    Josef Dalcolmo, Jun 15, 2004, in forum: Python
    Replies:
    0
    Views:
    306
    Josef Dalcolmo
    Jun 15, 2004
  3. Tim Golden

    RE: computer names and samba shares

    Tim Golden, Jun 16, 2004, in forum: Python
    Replies:
    2
    Views:
    336
    Josef Dalcolmo
    Jun 16, 2004
  4. =?iso-8859-1?q?WEBER_S=E9bastien?=

    SAMBA-PYTHON ???

    =?iso-8859-1?q?WEBER_S=E9bastien?=, Mar 4, 2007, in forum: Python
    Replies:
    1
    Views:
    514
    Jorge Godoy
    Mar 4, 2007
  5. Josef Moellers

    Restart Perl Application upon KDE Restart

    Josef Moellers, Jul 18, 2013, in forum: Perl Misc
    Replies:
    18
    Views:
    260
    Adam H. Kerman
    Jul 26, 2013
Loading...

Share This Page