Ubuntu - Run command on start-up with “sudo”

六眼飞鱼酱① 提交于 2019-12-17 17:28:33

问题


I would like to run a sudo command when Ubuntu starts up (before anyone logs in):

sudo searchd

How would I do this?


回答1:


You can add the command in the /etc/rc.local script that is executed at the end of startup.

Write the command before exit 0. Anything written after exit 0 will never be executed.




回答2:


Edit the tty configuration in /etc/init/tty*.conf with a shellscript as a parameter :

(...)
exec /sbin/getty -n -l  theInputScript.sh -8 38400 tty1
(...)

This is assuming that we're editing tty1 and the script that reads input is theInputScript.sh.

A word of warning this script is run as root, so when you are inputing stuff to it you have root priviliges. Also append a path to the location of the script.

Important: the script when it finishes, has to invoke the /sbin/login otherwise you wont be able to login in the terminal.



来源:https://stackoverflow.com/questions/9683357/ubuntu-run-command-on-start-up-with-sudo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!