Reputation: 91
Am trying to shutdown and boot it again the Linux system using python language or shell script. can anyone clarify me in this ? even crontab is also okay
Upvotes: 8
Views: 37819
Reputation: 61
You need two things to make your linux system to reboot.
1 - Give the user executing your script the privilege for reboot
$ sudo visudo -f /etc/sudoers.d/reboot_privilege
add line :
<user> ALL=(root) NOPASSWD: /sbin/reboot
2 - Execute the python code :
import os
os.system("sudo reboot")
It will reboot your system without any prompt nor check password.
Upvotes: 6
Reputation: 3344
If you don't want to give root privileges to the python process, you can use systemctl reboot -i
.
import os
os.system('systemctl reboot -i')
However, this will ignore all inhibitors, including other users logged in, etc. Use with caution.
Upvotes: 6
Reputation: 518
shell
reboot
python
import os
os.system('reboot')
Note: You need root permission to do reboot operation.
You should take some time to learn Linux basic concepts
first.
Upvotes: 18