``` if grep -q "auth sufficient pam_rootok.so" /etc/pam.d/su then sed -i '/auth sufficient pam_rootok.so/s/^#//' /etc/pam.d/su else echo 'auth sufficient pam_rootok.so' >> /etc/pam.d/su fi if grep -q "auth required pam_wheel.so group=wheel" /etc/pam.d/su then sed -i '/auth required pam_wheel.so group=wheel/s/^#//' /etc/pam.d/su else echo 'auth required pam_wheel.so group=wheel' >> /etc/pam.d/su fi if grep -q "export TMOUT=300" /etc/profile then sed -i '/export TMOUT=300/s/^#//' /etc/profile else echo 'export TMOUT=300' >> /etc/profile fi source /etc/profile ```
时间: 2023-09-18 14:06:56 浏览: 49
这段脚本的作用是对一些文件进行修改或添加配置,并且立即应用这些修改。具体解释如下:
1. 首先,检查/etc/pam.d/su文件中是否存在"auth sufficient pam_rootok.so"这一行。如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释;如果不存在,则在文件末尾添加一行"auth sufficient pam_rootok.so"。
2. 接着,检查/etc/pam.d/su文件中是否存在"auth required pam_wheel.so group=wheel"这一行。如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释;如果不存在,则在文件末尾添加一行"auth required pam_wheel.so group=wheel"。
3. 然后,检查/etc/profile文件中是否存在"export TMOUT=300"这一行。如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释;如果不存在,则在文件末尾添加一行"export TMOUT=300"。
4. 最后,使用source命令重新加载/etc/profile文件,以使修改立即生效。
这段脚本的目的是修改或添加一些系统配置,例如su命令的授权和超时时间的设置,并且立即应用这些修改。
相关问题
grep -q "auth sufficient pam_rootok.so" /etc/pam.d/su
这个命令是在 `/etc/pam.d/su` 文件中查找是否存在包含字符串 "auth sufficient pam_rootok.so" 的行,并且使用了 `-q` 选项来禁止输出结果。
具体而言,`grep` 命令用于在文件中搜索指定的模式。在这个命令中,我们搜索的模式是 "auth sufficient pam_rootok.so",文件路径是 `/etc/pam.d/su`。使用 `-q` 选项可以使 `grep` 命令在找到匹配的内容后保持静默,不会输出结果。
如果命令执行成功且没有产生输出,那么表示 `/etc/pam.d/su` 文件中存在一行包含 "auth sufficient pam_rootok.so" 的内容。如果没有找到匹配的内容或者命令执行失败,那么不会有任何输出。
请注意,执行此命令需要有足够的权限访问 `/etc/pam.d/su` 文件。
逐条注释 ``` if grep -q "auth sufficient pam_rootok.so" /etc/pam.d/su then sed -i '/auth sufficient pam_rootok.so/s/^#//' /etc/pam.d/su else echo 'auth sufficient pam_rootok.so' >> /etc/pam.d/su fi if grep -q "auth required pam_wheel.so group=wheel" /etc/pam.d/su then sed -i '/auth required pam_wheel.so group=wheel/s/^#//' /etc/pam.d/su else echo 'auth required pam_wheel.so group=wheel' >> /etc/pam.d/su fi if grep -q "export TMOUT=300" /etc/profile then sed -i '/export TMOUT=300/s/^#//' /etc/profile else echo 'export TMOUT=300' >> /etc/profile fi source /etc/profile ```
这段脚本的作用是对指定的文件进行修改或添加配置,并且立即应用这些修改。下面是对每个部分逐条进行注释:
```shell
if grep -q "auth sufficient pam_rootok.so" /etc/pam.d/su
then
sed -i '/auth sufficient pam_rootok.so/s/^#//' /etc/pam.d/su
else
echo 'auth sufficient pam_rootok.so' >> /etc/pam.d/su
fi
```
- 检查/etc/pam.d/su文件中是否存在"auth sufficient pam_rootok.so"这一行。
- 如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释。
- 如果不存在,则在文件末尾添加一行"auth sufficient pam_rootok.so"。
```shell
if grep -q "auth required pam_wheel.so group=wheel" /etc/pam.d/su
then
sed -i '/auth required pam_wheel.so group=wheel/s/^#//' /etc/pam.d/su
else
echo 'auth required pam_wheel.so group=wheel' >> /etc/pam.d/su
fi
```
- 检查/etc/pam.d/su文件中是否存在"auth required pam_wheel.so group=wheel"这一行。
- 如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释。
- 如果不存在,则在文件末尾添加一行"auth required pam_wheel.so group=wheel"。
```shell
if grep -q "export TMOUT=300" /etc/profile
then
sed -i '/export TMOUT=300/s/^#//' /etc/profile
else
echo 'export TMOUT=300' >> /etc/profile
fi
```
- 检查/etc/profile文件中是否存在"export TMOUT=300"这一行。
- 如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释。
- 如果不存在,则在文件末尾添加一行"export TMOUT=300"。
```shell
source /etc/profile
```
- 重新加载/etc/profile文件,使修改立即生效。
这段脚本的目的是修改或添加一些系统配置,例如su命令的授权和超时时间的设置,并且立即应用这些修改。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)