我是靠谱客的博主 俊秀毛巾,这篇文章主要介绍liunx开机自动运行命令,现在分享给大家,希望可以做个参考。

1. 通用方法: [root@localhost ~]# vim /etc/rc.d/rc.local

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
touch /var/lock/subsys/local # 自动挂载命令 mkdir /xxx mkdir /var/log/xxx for ((i=1; i<=5; i++));do ping xxx.xx.x.xxx -c 2 | grep -q "ttl=" && echo "CIFS_Server $CIFS_IP is active" >> /var/log/xxx /dhcp.log && break dhclient sleep 5 echo "CIFS_Server xxx.xx.x.xxx is not active" >> /var/log/xxx/dhcp.log done mount -t cifs -o vers=2.0,username=xxx,password=xxx,sec=ntlmssp,cache=none,nobrl //xxx.xx.x.xxx/xxx /xxx for ((i=1; i<=3; i++));do if [[ "$?" -ne 0 ]];then echo "mount /xxx fail" >> /var/log/xxx/dhcp.log sleep 5 mount -t cifs -o vers=2.0,username=xxx,password=xxx,sec=ntlmssp,cache=none,nobrl //xxx.xx.x.xxx/xxx /xxx else echo "mount /xxx success" >> /var/log/xxx/dhcp.log break fi done

设置状态命令:[root@localhost ~]#systemctl status rc-local

2.进阶启动命令设置(注意:运行脚本里需要手动输入指令时)

[root@localhost ~]# vim autotest.sh

复制代码
1
2
3
4
5
6
7
8
9
#!/bin/bash rm -rf /var/log/xxx/xxx.log cd /root/xxx userNum="" processID=$(ps -ef | grep xxx.py | grep -v "grep" | awk "{print $2}") if [ -z "$processID" ];then python xxx.py fi

[root@localhost ~]# vim /etc/profile

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
autotestfile="/root/xxx/autotest.sh" # 自动运行本脚本 # autotestfile = '/root/xxx/xxx.py' if [ -f "$autotestfile" ];then sh $autotestfile python autotestfile fi unset i unset -f pathmunge

写完脚本后,开始reboot重启进行检查,命令如下

[root@localhost ~]# ps -aux | grep xxx.py

复制代码
1
2
3
root 3510 0.0 0.1 196356 9732 pts/0 S+ 20:51 0:00 python xxx.py root 3829 0.0 0.0 112812 984 pts/1 S+ 21:03 0:00 grep --color=auto xxx.py

简洁方法~忽略上述:

复制代码
1
2
3
4
5
6
7
8
9
10
[root@localhost]# vim /etc/profile autotestfile="/root/xxx.py" filePath="/root/xxx" if [ -f "$autotestfile" ];then cd $filePath python $autotestfile fi

今日汇总完毕 !!!

最后

以上就是俊秀毛巾最近收集整理的关于liunx开机自动运行命令的全部内容,更多相关liunx开机自动运行命令内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部