一.设置开机自启动
1.赋予脚本可执行权限(/root/autostart.sh是你的脚本路径)
chmod +x /root/autostart.sh
2.打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/root/autostart.sh
3.在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
chmod +x /etc/rc.d/rc.local
上述方法现在已不建议使用,更推荐使用systemd的方式。
第一步,创建service文件
vi /etc/systemd/system/myautostart.service
第二步,粘贴插入以下代码
[Unit]
Description=myautostart service
After=caddy.service
[Service]
Type=forking
ExecStart=/bin/sh /root/autostart.sh
[Install]
WantedBy=multi-user.target
第三步,配置服务自启动
开机启动:systemctl enable myautostart
启动:systemctl start myautostart
关闭:systemctl stop myautostart
重启:systemctl restart myautostart
查看状态:systemctl status myautostart
修改服务配置重新生效:systemctl daemon-reload
二.清除命令记录
1.清除登陆系统成功的记录
echo > /var/log/wtmp
2.清除登陆系统失败的记录
echo > /var/log/btmp
3.清除历史执行命令
echo > ./.bash_history
三.常用命令记录
1.后台启动
nohup
2.后台启动且不输出日志
nohup xxx.sh 1>/dev/null 2>&1 &
本文由 转啊转 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2016/10/18 09:30