linux系统,要让它登录自动运行两条shell命令,该怎么办?
答案:3 悬赏:40
解决时间 2021-01-27 01:06
- 提问者网友:了了无期
- 2021-01-26 06:33
linux系统,要让它登录自动运行两条shell命令,该怎么办?
最佳答案
- 二级知识专家网友:煞尾
- 2021-01-26 07:46
只需要3步,已经验证成功:
1、编写/root/addRoute.sh(内容是需要自动执行的命令)如下:
route add default gw 192.1.2.254
2、授权:chmod 777 /root/addRoute.sh
3、在/etc/rc.d/rc.local加入脚本执行命令,如下面最后一行(注意是全路径,如/bin/sh):
[root@jk ~]# cat /etc/rc.d/rc.local #!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch /var/lock/subsys/local
/bin/sh /root/addRoute.sh
追问:/bin/sh 是用户登录的shell么?
追答:用户登录的shell是可以用于用户登录使用的,比如 /bin/bash ,/bin/sh ,/bin/csh ……一般Linux默认的用户shell都是bash ,也就是说你可以登录进去敲命令。
1、编写/root/addRoute.sh(内容是需要自动执行的命令)如下:
route add default gw 192.1.2.254
2、授权:chmod 777 /root/addRoute.sh
3、在/etc/rc.d/rc.local加入脚本执行命令,如下面最后一行(注意是全路径,如/bin/sh):
[root@jk ~]# cat /etc/rc.d/rc.local #!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch /var/lock/subsys/local
/bin/sh /root/addRoute.sh
追问:/bin/sh 是用户登录的shell么?
追答:用户登录的shell是可以用于用户登录使用的,比如 /bin/bash ,/bin/sh ,/bin/csh ……一般Linux默认的用户shell都是bash ,也就是说你可以登录进去敲命令。
全部回答
- 1楼网友:等灯
- 2021-01-26 09:45
写在/etc/rc.local中?
- 2楼网友:街头电车
- 2021-01-26 09:22
说详细点,你要实现一个什么目的? 先确认一下,你的linux是RedHat系,还是Debain系的?
追问:redhat系统,每次开机要进行网卡驱动的删除和加载,不然网络不通。
追答:那你就可以像楼上说的那样,把删除和加载的shell脚本,设定好执行权限,放在/etc/rc.local目录下,每次开机所有服务都启动之后,最后会自动运行/etc/rc.local的脚本程序。
追问:
这样?
追问:redhat系统,每次开机要进行网卡驱动的删除和加载,不然网络不通。
追答:那你就可以像楼上说的那样,把删除和加载的shell脚本,设定好执行权限,放在/etc/rc.local目录下,每次开机所有服务都启动之后,最后会自动运行/etc/rc.local的脚本程序。
追问:
这样?
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯