linux启动脚本如何写

linux启动脚本如何写,第1张

第1种:直接写入 rc.local 文件 如:echo " ls -la >/tmp/a.txt " >>/etc/rc.local(这种是直接把命令写入启动文件rc.local中,当然也可以引申为 将命令直接写入到sh文件,再加上执行权限,将这个全路径文件名写入rc.local也一样) 第2种:先使用runlevel 查看正常启动所运行的级别上,再在/etc/rc*.d(星号代表运行级别,各系统可能存在差异)的目录中新加入(不是写入)启动文件以S开头的文件。这种方法稍稍复杂点。

/sbin/insmod ./$module.ko $* || exit 1

* 代表任意, 匹配所有参数, $变量,在shell中取变量的值

“&&” and “||” are AND-OR list operators.

“&&” executes the first command, and then executes the second command iff the exit status of

the first command is zero.

“||” is similar, but executes the second command iff the exit status of the first command is nonzero.

“&&” and “||” both have the same priority.

|| 表示前面插入出错返回非0,则exit 1退出

major=$(awk "\\$2==\"$module\" {print \\$1}" /proc/devices)

\为转义字符 \\就是\,

转义字符的值为后面的值

\"就是"

/表示目录层次

首先脚本需要有执行权限:chmod u x file.sh;方法:

用shell程序执行脚本:根据你的shell脚本的类型,选择shell程序,常用的有sh,bash,tcsh等然后输入命令(其中bash为shell的名称,myshell.sh则为你要执行的代码):bash myshell.sh


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7598821.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-07
下一篇2023-04-07

发表评论

登录后才能评论

评论列表(0条)

    保存