parent
2a51bc1879
commit
30707ce7be
@ -0,0 +1,47 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
# 定义检查函数 |
||||||
|
check_command() { |
||||||
|
if eval $1; then |
||||||
|
echo "第$2题正确" |
||||||
|
else |
||||||
|
echo "第$2题错误" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# 1. 检查是否为root用户并且当前目录是否为/opt |
||||||
|
check_command "[ $(id -u) -eq 0 ]" 1 |
||||||
|
|
||||||
|
# 2. 检查用户tom和jack以及组hr是否存在,并且tom是否属于组hr |
||||||
|
check_command "id tom &>/dev/null && id jack &>/dev/null && grep hr /etc/group &>/dev/null" 2 |
||||||
|
|
||||||
|
# 3. 检查目录/opt/myfile和文件hello.txt、world.txt是否存在 |
||||||
|
check_command "[ -d /opt/myfile ] && [ -f /opt/myfile/hello.txt ] && [ -f /opt/world.txt ]" 3 |
||||||
|
|
||||||
|
# 4. 检查world.txt文件是否包含abcde字符串,且重复10行 |
||||||
|
check_command "grep -Fxq 'abcde' /opt/world.txt && [ \$(grep -c 'abcde' /opt/world.txt) -eq 10 ]" 4 |
||||||
|
|
||||||
|
# 5. 检查world.txt文件的属主是否为jack,属组是否为hr |
||||||
|
check_command "[ \$(stat -c '%U' /opt/world.txt) = 'jack' ] && [ \$(stat -c '%G' /opt/world.txt) = 'hr' ]" 5 |
||||||
|
|
||||||
|
# 6. 检查world.txt文件权限是否设置正确 |
||||||
|
check_command "[ \$(stat -c '%A' /opt/world.txt) = '-rwxrw-r--' ]" 6 |
||||||
|
|
||||||
|
# 7. 检查/opt/myfile目录的属组是否为hr,并且递归设置 |
||||||
|
check_command "[ \$(stat -c '%G' /opt/myfile) = 'hr' ] && [ \$(find /opt/myfile -not -group hr | wc -l) -eq 1 ]" 7 |
||||||
|
|
||||||
|
# 8. 检查/opt/myfile目录的权限是否允许所有用户创建文件或子目录,且新文件继承属组 |
||||||
|
check_command "[ \$(stat -c '%a' /opt/myfile) = '2777' ]" 8 |
||||||
|
|
||||||
|
# 9. 检查cat命令是否设置为特殊提权指令 |
||||||
|
check_command "find / -perm -4000 2>/dev/null| grep -qw 'cat'" 9 |
||||||
|
|
||||||
|
# 10. 检查world.txt的后5行是否被复制到hello.txt中 |
||||||
|
check_command "head -n 5 /opt/myfile/hello.txt | grep abcde &>/dev/null" 10 |
||||||
|
|
||||||
|
# 11. 检查ip地址信息是否追加到hello.txt文件中 |
||||||
|
check_command "grep ens33 /opt/myfile/hello.txt &>/dev/null" 11 |
||||||
|
|
||||||
|
# 12. 检查/opt目录下的所有内容是否复制到/mnt目录下 |
||||||
|
check_command "[ \$(diff -r /opt /mnt | wc -l) -eq 0 ]" 12 |
||||||
|
|
Loading…
Reference in new issue