By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

cron, python and samba restart

P: n/a
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()

Oct 27 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
symbioid <sy******@gmail.comwrote:
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/su...ay/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 <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Oct 29 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.