Getting subprocess.Popen stdout when running by cron
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to get a service status and if it's not up, to send the status (stdout) in email.
This script is scheduled to run every hour by cron.
When running manually, the following works fine:
def is_service_running(name):
with open(os.devnull, 'wb') as hide_output:
proc = subprocess.Popen(['service', name, 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output = proc.stdout.read()
exit_code = proc.wait()
return exit_code == 0, output
But when running by cron. output
is empty.
How can I capture stdout
when running by cron?
Thank you
linux cron python stdout
add a comment |Â
up vote
0
down vote
favorite
I want to get a service status and if it's not up, to send the status (stdout) in email.
This script is scheduled to run every hour by cron.
When running manually, the following works fine:
def is_service_running(name):
with open(os.devnull, 'wb') as hide_output:
proc = subprocess.Popen(['service', name, 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output = proc.stdout.read()
exit_code = proc.wait()
return exit_code == 0, output
But when running by cron. output
is empty.
How can I capture stdout
when running by cron?
Thank you
linux cron python stdout
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get a service status and if it's not up, to send the status (stdout) in email.
This script is scheduled to run every hour by cron.
When running manually, the following works fine:
def is_service_running(name):
with open(os.devnull, 'wb') as hide_output:
proc = subprocess.Popen(['service', name, 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output = proc.stdout.read()
exit_code = proc.wait()
return exit_code == 0, output
But when running by cron. output
is empty.
How can I capture stdout
when running by cron?
Thank you
linux cron python stdout
I want to get a service status and if it's not up, to send the status (stdout) in email.
This script is scheduled to run every hour by cron.
When running manually, the following works fine:
def is_service_running(name):
with open(os.devnull, 'wb') as hide_output:
proc = subprocess.Popen(['service', name, 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output = proc.stdout.read()
exit_code = proc.wait()
return exit_code == 0, output
But when running by cron. output
is empty.
How can I capture stdout
when running by cron?
Thank you
linux cron python stdout
asked Jun 14 at 15:14
SagiLow
1537
1537
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22
add a comment |Â
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
The problem wasn't cron but shell=True
.
Apparently, when using shell=True
, popen expects single string and not a list.
So when I updated my call to:
proc = subprocess.Popen(['service ' + name + ' status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
everything worked.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The problem wasn't cron but shell=True
.
Apparently, when using shell=True
, popen expects single string and not a list.
So when I updated my call to:
proc = subprocess.Popen(['service ' + name + ' status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
everything worked.
add a comment |Â
up vote
0
down vote
The problem wasn't cron but shell=True
.
Apparently, when using shell=True
, popen expects single string and not a list.
So when I updated my call to:
proc = subprocess.Popen(['service ' + name + ' status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
everything worked.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The problem wasn't cron but shell=True
.
Apparently, when using shell=True
, popen expects single string and not a list.
So when I updated my call to:
proc = subprocess.Popen(['service ' + name + ' status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
everything worked.
The problem wasn't cron but shell=True
.
Apparently, when using shell=True
, popen expects single string and not a list.
So when I updated my call to:
proc = subprocess.Popen(['service ' + name + ' status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
everything worked.
answered Jun 15 at 9:22
SagiLow
1537
1537
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449836%2fgetting-subprocess-popen-stdout-when-running-by-cron%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Is it because /usr/sbin is in your interactive environment but not cronâÂÂs?
â Jeff Schaller
Jun 14 at 17:58
Hi @JeffSchaller, no idea.. that's why i'm asking :)
â SagiLow
Jun 15 at 9:14
I think you should see if that popen call is successful. Maybe also use the full path to the service command.
â Jeff Schaller
Jun 15 at 9:21
@JeffSchaller You were close, see the answer
â SagiLow
Jun 15 at 9:22