@reboot does not work on cron.

Asked 1 years ago, Updated 1 years ago, 92 views

Nice to meet you
I am a beginner in Linux, and I have a question because I didn't see any similar cases online.

On the raspies

 sudo crontab-e

Launch the editor from the and

10***/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py;

Python works when you set it to , but you can see the above

@reboot/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py;

does not work on reboot.

What kind of confirmation should I make?
The cron.log is as follows:

■ Normal operation

 Jun 12 16:34:01 raspberrypi CRON [1695]: (root) CMD (/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py;)

■ When setting @reboot

 Jun 12 17:17:07 raspberrypicron [412]: (CRON) INFO (pidfile fd=3)
Jun 12 17:17:07 raspberrypicron [412]: (CRON) INFO (Running@reboot jobs)
Jun 12 17:17:07 raspberrypi CRON [464]: (root) CMD (/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py;)
Jun 12 17:17:09 raspberrypi CRON [423]: (root) MAIL (mailed 785 bytes of output but got status 0x0001 from MTA#012)

That's all.
Thank you for your cooperation.

追Additional
Dear @take88 and @masm
Thank you for pointing it out.

    I checked
  • /var/spool/mail/root, but the file did not exist
  • I tried to delete the ending ";", but it didn't improve.
  • @reboot/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py>/tmp/room-pub.log2>&1 I changed it to

  • <

    socket.gaierror: [Errno-2] Name or service not known

@reboot/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py>/tmp/room-pub.log2>&1 I changed the code to the following. Could you tell me what this sentence means?

socket.gaierror: [Errno-2] Name or service not known

Thank you for your cooperation.

python linux raspberry-pi python3 cron

2022-09-29 21:19

2 Answers

If there is an error running cron, you may have received an email at root.

Typically, mail is stored in the /var/spool/mail/root file.
If you have a file, please check the contents with less.
If you see a cron runtime error, that's a hint.


2022-09-29 21:19

Looking at the cron log, @reboot seems to be working.

First of all, I support take88's answer, but if you don't have that file, you should try the following.

  • Try removing the trailing ;

    I don't think this ; would be harmful, but just in case.
    If this doesn't work,

  • Try changing to

  • @reboot/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py>/tmp/room-pub.log2>&1

    If you haven't received the mail, you should try to print the standard output and the standard error output to the file like this way.
    If /tmp/room-pub.log has been created, you will see some kind of error in it.

Try deleting the ending ;

I don't think this ; would be harmful, but just in case.
If this doesn't work,

Try changing to @reboot/usr/bin/python3/home/pi/Desktop/seminar/room-pub.py>/tmp/room-pub.log2>&1

If you haven't received the mail, you should try to print the standard output and the standard error output to the file like this way.
If /tmp/room-pub.log has been created, you will see some kind of error in it.

This is an answer to the comment.

Name or service not known is often seen when hostnames cannot be resolved.
Perhaps you are doing something with the network within room-pub.py, but the network is not ready right after reboot and you cannot contact DNS?


2022-09-29 21:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.