cron, python and samba restart

S

symbioid

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()
 
N

Nick Craig-Wood

symbioid said:
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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top