473,395 Members | 1,689 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,395 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 2686
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.