Output print statement in python does not goes into cron log












1















my crontab looks like this:



@reboot sh /home/pi/LCDinterface/shutdownlauncher.sh 2>&1 | tee -a /home/cronlog


Content of shutdownlauncher.sh :



cd /
cd home/pi/LCDinterface


date
python shutdown.py
echo ''
cd /


Content of shutdown.py :



if interrupt_happens:
print ("shutting down")
time.sleep(3)
os.system("sudo shutdown -h now")


If I run python shutdown.py or sh shutdownlauncher.sh I can always see the output text 'shutting down' in my terminal. But If only cron starts running the bash script, which calls the python script. I never see the text, and it does not appear in the log. The date command in sh script appears in my log, but not in the terminal. Can you help me with that? How to edit the shutdownlauncher.sh or the cron job to see the outputs in the terminal, and in the log too? This whole thing runs on a Raspberry Pi 3, I am connected on SSH.



Content of my log file:



Fri Apr  7 19:26:33 CEST 2017
Fri Apr 7 19:36:11 CEST 2017
Fri Apr 7 21:18:45 CEST 2017
Sat Apr 8 00:08:09 CEST 2017
Sat Apr 8 00:29:31 CEST 2017
Sat Apr 8 10:08:17 CEST 2017
Sat Apr 8 11:58:35 CEST 2017









share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

    – Kusalananda
    Apr 8 '17 at 17:33













  • What "terminal" are you expecting the output to be shown on?

    – terdon
    Apr 8 '17 at 17:51
















1















my crontab looks like this:



@reboot sh /home/pi/LCDinterface/shutdownlauncher.sh 2>&1 | tee -a /home/cronlog


Content of shutdownlauncher.sh :



cd /
cd home/pi/LCDinterface


date
python shutdown.py
echo ''
cd /


Content of shutdown.py :



if interrupt_happens:
print ("shutting down")
time.sleep(3)
os.system("sudo shutdown -h now")


If I run python shutdown.py or sh shutdownlauncher.sh I can always see the output text 'shutting down' in my terminal. But If only cron starts running the bash script, which calls the python script. I never see the text, and it does not appear in the log. The date command in sh script appears in my log, but not in the terminal. Can you help me with that? How to edit the shutdownlauncher.sh or the cron job to see the outputs in the terminal, and in the log too? This whole thing runs on a Raspberry Pi 3, I am connected on SSH.



Content of my log file:



Fri Apr  7 19:26:33 CEST 2017
Fri Apr 7 19:36:11 CEST 2017
Fri Apr 7 21:18:45 CEST 2017
Sat Apr 8 00:08:09 CEST 2017
Sat Apr 8 00:29:31 CEST 2017
Sat Apr 8 10:08:17 CEST 2017
Sat Apr 8 11:58:35 CEST 2017









share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

    – Kusalananda
    Apr 8 '17 at 17:33













  • What "terminal" are you expecting the output to be shown on?

    – terdon
    Apr 8 '17 at 17:51














1












1








1








my crontab looks like this:



@reboot sh /home/pi/LCDinterface/shutdownlauncher.sh 2>&1 | tee -a /home/cronlog


Content of shutdownlauncher.sh :



cd /
cd home/pi/LCDinterface


date
python shutdown.py
echo ''
cd /


Content of shutdown.py :



if interrupt_happens:
print ("shutting down")
time.sleep(3)
os.system("sudo shutdown -h now")


If I run python shutdown.py or sh shutdownlauncher.sh I can always see the output text 'shutting down' in my terminal. But If only cron starts running the bash script, which calls the python script. I never see the text, and it does not appear in the log. The date command in sh script appears in my log, but not in the terminal. Can you help me with that? How to edit the shutdownlauncher.sh or the cron job to see the outputs in the terminal, and in the log too? This whole thing runs on a Raspberry Pi 3, I am connected on SSH.



Content of my log file:



Fri Apr  7 19:26:33 CEST 2017
Fri Apr 7 19:36:11 CEST 2017
Fri Apr 7 21:18:45 CEST 2017
Sat Apr 8 00:08:09 CEST 2017
Sat Apr 8 00:29:31 CEST 2017
Sat Apr 8 10:08:17 CEST 2017
Sat Apr 8 11:58:35 CEST 2017









share|improve this question
















my crontab looks like this:



@reboot sh /home/pi/LCDinterface/shutdownlauncher.sh 2>&1 | tee -a /home/cronlog


Content of shutdownlauncher.sh :



cd /
cd home/pi/LCDinterface


date
python shutdown.py
echo ''
cd /


Content of shutdown.py :



if interrupt_happens:
print ("shutting down")
time.sleep(3)
os.system("sudo shutdown -h now")


If I run python shutdown.py or sh shutdownlauncher.sh I can always see the output text 'shutting down' in my terminal. But If only cron starts running the bash script, which calls the python script. I never see the text, and it does not appear in the log. The date command in sh script appears in my log, but not in the terminal. Can you help me with that? How to edit the shutdownlauncher.sh or the cron job to see the outputs in the terminal, and in the log too? This whole thing runs on a Raspberry Pi 3, I am connected on SSH.



Content of my log file:



Fri Apr  7 19:26:33 CEST 2017
Fri Apr 7 19:36:11 CEST 2017
Fri Apr 7 21:18:45 CEST 2017
Sat Apr 8 00:08:09 CEST 2017
Sat Apr 8 00:29:31 CEST 2017
Sat Apr 8 10:08:17 CEST 2017
Sat Apr 8 11:58:35 CEST 2017






shell-script cron logs raspberry-pi stdout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 8 '17 at 17:48









Jeff Schaller

41.5k1056132




41.5k1056132










asked Apr 8 '17 at 17:15









user3598726user3598726

1064




1064





bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

    – Kusalananda
    Apr 8 '17 at 17:33













  • What "terminal" are you expecting the output to be shown on?

    – terdon
    Apr 8 '17 at 17:51



















  • Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

    – Kusalananda
    Apr 8 '17 at 17:33













  • What "terminal" are you expecting the output to be shown on?

    – terdon
    Apr 8 '17 at 17:51

















Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

– Kusalananda
Apr 8 '17 at 17:33







Why would you want to run shutdown on boot? A @reboot cron-job runs when the machine is booting up.

– Kusalananda
Apr 8 '17 at 17:33















What "terminal" are you expecting the output to be shown on?

– terdon
Apr 8 '17 at 17:51





What "terminal" are you expecting the output to be shown on?

– terdon
Apr 8 '17 at 17:51










1 Answer
1






active

oldest

votes


















0














Instead of print function try use module syslog.



import syslog
syslog.syslog('System is going to shutdown')





share|improve this answer
























  • I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

    – user3598726
    Apr 8 '17 at 17:40













  • Give the full path to python in your shutdownlauncher.sh script.

    – user218374
    Apr 8 '17 at 17:43











  • why do you want to use python to shutdown system? If you need delay, shutdown provides it

    – darvark
    Apr 8 '17 at 17:43











  • If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

    – user3598726
    Apr 8 '17 at 17:50













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f357800%2foutput-print-statement-in-python-does-not-goes-into-cron-log%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Instead of print function try use module syslog.



import syslog
syslog.syslog('System is going to shutdown')





share|improve this answer
























  • I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

    – user3598726
    Apr 8 '17 at 17:40













  • Give the full path to python in your shutdownlauncher.sh script.

    – user218374
    Apr 8 '17 at 17:43











  • why do you want to use python to shutdown system? If you need delay, shutdown provides it

    – darvark
    Apr 8 '17 at 17:43











  • If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

    – user3598726
    Apr 8 '17 at 17:50


















0














Instead of print function try use module syslog.



import syslog
syslog.syslog('System is going to shutdown')





share|improve this answer
























  • I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

    – user3598726
    Apr 8 '17 at 17:40













  • Give the full path to python in your shutdownlauncher.sh script.

    – user218374
    Apr 8 '17 at 17:43











  • why do you want to use python to shutdown system? If you need delay, shutdown provides it

    – darvark
    Apr 8 '17 at 17:43











  • If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

    – user3598726
    Apr 8 '17 at 17:50
















0












0








0







Instead of print function try use module syslog.



import syslog
syslog.syslog('System is going to shutdown')





share|improve this answer













Instead of print function try use module syslog.



import syslog
syslog.syslog('System is going to shutdown')






share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 8 '17 at 17:24









darvarkdarvark

1875




1875













  • I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

    – user3598726
    Apr 8 '17 at 17:40













  • Give the full path to python in your shutdownlauncher.sh script.

    – user218374
    Apr 8 '17 at 17:43











  • why do you want to use python to shutdown system? If you need delay, shutdown provides it

    – darvark
    Apr 8 '17 at 17:43











  • If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

    – user3598726
    Apr 8 '17 at 17:50





















  • I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

    – user3598726
    Apr 8 '17 at 17:40













  • Give the full path to python in your shutdownlauncher.sh script.

    – user218374
    Apr 8 '17 at 17:43











  • why do you want to use python to shutdown system? If you need delay, shutdown provides it

    – darvark
    Apr 8 '17 at 17:43











  • If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

    – user3598726
    Apr 8 '17 at 17:50



















I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

– user3598726
Apr 8 '17 at 17:40







I tried it, It did not help unfortunately. I suspect python scipt does not actully returns becouse of the shutdown, all my other cronlogs looks nice, and they work the same way: bash script call python scripts with simple prints

– user3598726
Apr 8 '17 at 17:40















Give the full path to python in your shutdownlauncher.sh script.

– user218374
Apr 8 '17 at 17:43





Give the full path to python in your shutdownlauncher.sh script.

– user218374
Apr 8 '17 at 17:43













why do you want to use python to shutdown system? If you need delay, shutdown provides it

– darvark
Apr 8 '17 at 17:43





why do you want to use python to shutdown system? If you need delay, shutdown provides it

– darvark
Apr 8 '17 at 17:43













If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

– user3598726
Apr 8 '17 at 17:50







If I print sys. executable I always get back the same path, so the python version is ok, but i will try it. I use python to shut down, becouse I use GPIO interrupt on raspberry to start the shutdown, it was easy to do in python , works well, only print statement is missing

– user3598726
Apr 8 '17 at 17:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f357800%2foutput-print-statement-in-python-does-not-goes-into-cron-log%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux