0

I have written a Python program to restart the server running on Ubuntu 18.04 using: os.system("shutdown -r -t 1").

When the service is loaded the program OS is not restarting, but on the independent running of the program it is working fine.

The service log shows:

Nov 18 12:51:51 jetson-desktop python3[13004]: Failed to set wall message, ignoring: Interactive authentication required.
Nov 18 12:51:51 jetson-desktop python3[13004]: Failed to call ScheduleShutdown in logind, proceeding with immediate shutdown: Interactive authentication required.
Nov 18 12:52:44 jetson-desktop python3[13004]: Failed to set wall message, ignoring: Interactive authentication required.
Nov 18 12:52:44 jetson-desktop python3[13004]: Failed to call ScheduleShutdown in logind, proceeding with immediate shutdown: Interactive authentication required.

Whats going wrong?

0

The shutdown command requires elevated privileges.

Imagine, in a multi user environment, which a Linux system is, every logged in user could shutdown or reboot the machine - this would be fatal.

So, basically you need to get elevated privileges.

This question has been answered many times. Here is a good thread:

https://stackoverflow.com/questions/25215604/use-sudo-without-password-inside-a-script

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.