Ubuntu 常用

Ubuntu 常用

1. 开机自动运行

way 1. rc.local

在 /etc/rc.local 下添加 要运行的命令,即可开机自动执行这些命令。

如:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
cd  /soft/nat123    --本地实际安装目录
mono  nat123linux.sh  service  &      ---自动读取上次成功登录帐号并以后台服务启动
exit 0

例外情况,可能会etc下没有 rc.local 文件,则需要按以下步骤启动 rc.local 服务

1、设置rc-local.service

创建并编辑 sudo vim /etc/systemd/system/rc-local.service

将以下内容复制进去

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

2、激活rc-local.service

sudo systemctl enable rc-local.service

3、添加启动服务

手工创建或者拷贝已有的/etc/rc.local,并赋予执行权限

#!/bin/sh -e
# 
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# 下面这条是要开机启动的命令
/home/selfcs/anaconda3/bin/Python /home/selfcs/t.py > /home/selfcs/auto.log 

exit 0

4、给予脚本执行权限

sudo chmod +x /etc/rc.local

2. 用户登录自动运行

1. 在 /etc/profile 里编辑

2. 在 /etc/profile.d/下 添加 sh 脚本

3.

ps -ef | grep nat
ps -ef | grep xxx

kill -9
kill -15

xxx/xxx.sh &

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!