cron, python and samba restart
symbioid at gmail.com
Sat Oct 27 22:15:33 CEST 2007
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.
t = str(int(time.time()))
f = "gasr.dat"
file = open(f,'r')
timestamp = file.readline()
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')
More information about the Python-list