0

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
  • 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
0

Instead of print function try use module syslog.

import syslog
syslog.syslog('System is going to shutdown')
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.