脚本编程进阶
1、chmod -rw /tmp/file1,编写脚本/root/bin/per.sh,判断当前用户对/tmp/fiile1文件 是否不可读且不可写 #!/bin/bash [ ! -r /tmp/file1 ] && [ ! -w /tmp/file1 ] && echo "不可读写" || echo "可读写" [root@centos7 shell]# chmod -rw /tmp/file1 [root@centos7 shell]# ll /tmp/file1 ----------. 1 root root 0 Aug 10 16:22 /tmp/file1 [root@centos7 shell]# bash per.sh 可读写 [root@centos7 shell]# su cent [cent@centos7 shell]$ bash per.sh 不可读写 2、编写脚本/root/bin/nologin.sh和login.sh,实现禁止和充许普通用户登录系统 思路:当/etc/目录下存在 nologin 文件时,普通用户会无法登陆,因此,我们只需要通过删除或增加该文件来限制普通用户是否可登陆 [root@centos7 shell]# cat login.sh nologin.sh #!/bin/bash [ -e /etc/nologin ] && echo