473,287 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

cron, python and samba restart

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
1 2682
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Doug | last post by:
I have Windows XP professional. Is there ANYTHING reliable on Windows that is like cron on UNIX that will allow you run something at regular intervals, for example, like every 10 minutes? I...
10
by: martijn | last post by:
H! I'm using a windows machine. And a FreeBSD server where I run my python scripts. I'm working/making my python scripts in a windows OS with putty now. But I really want the python text...
1
by: Piotr Trawiński | last post by:
I have this notorious problem: at some point pgsql simply hangs up and requires a restart. --------------------------------------------------------------------------- -------...
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
2
by: erikcw | last post by:
Hi all, When trying to run this python script from cron, I get the following error: Traceback (most recent call last): File "/home/lybp/public_html/wa/wa.py", line 14, in ? import MySQLdb...
20
by: ram.rachum | last post by:
Hey, I'm looking for a good Python environment. That is, at least an editor and a debugger, and it should run on Windows. Does anyone have any idea?
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.