Ubuntu18设置开机运行命令

1.设置启动参数

nano /lib/systemd/system/rc.local.service 

 

[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=no
GuessMainPID=no
 
#这一段原文件没有,需要自己添加
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
 

 

2.设置软连接

ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/rc.local.service

 

3.编辑rc.local文件

nano /etc/rc.local

# 示例:

 

#!/bin/bash
systemctl start pptpd
/home/zhw/anaconda3/bin/python /home/zhw/login_shcool_net.py
nohup ping www.qq.com > /home/zhw/1 2>&1 &
exit 0

 

4.重启

试一把!

 

 

参考:

https://blog.csdn.net/idiot_qi/article/details/86527052

你可能感兴趣的:(Ubuntu,CentOS)