Script Name: power.sh
Script content:
The code is as follows:
#!/bin/sh
Username3=$1
Dir_name2=$2
# Get existing Directory
File_path= $dir _name2
While True
Todo
If [D-$file _path];then
Break
Fi
file_path=${file_path%/*}
Done
dir_name2= $file _path
# Judge whether the user exists
grep "^ $username 3:"/etc/passwd >/dev/null
If [$?-ne 0];then
echo "This user" $username 3 "does not exist."
Exit 4
Fi
#echo "Username: $username 3"
group4= ' grep ' ^ $username 3: "/etc/passwd |awk-f: {' Print $ '}|xargs-i grep {}/etc/group|cut-d": "-f1"
#echo "Group: $group 4"
Su-l $username 3-c "Test-r $dir _name2"
Is_read=$?
Su-l $username 3-c "Test-x $dir _name2"
Is_exe=$?
Su-l $username 3-c "test-w $dir _name2"
Is_write=$?
$is _read_str
$is _exe_str
$is _write_str
If [$is _read-eq 0];then
Is_read_str= "R"
Else
Is_read_str= "-"
Fi
If [$is _exe-eq 0];then
Is_exe_str= "X"
Else
Is_exe_str= "-"
Fi
If [$is _write-eq 0];then
Is_write_str= "W"
Else
Is_write_str= "-"
Fi
echo "${is_read_str}${is_write_str}${is_exe_str}"
-------------------------------------------
Note: This script must be executed as root.
Script power.sh requires two parameters, the first represents the specified user, and the second represents the specified directory
Test:
[Root@ppc40 study]# sh power.sh whuanga4/tmp/abc/dd
This user "Whuanga4" does not exist.
[Root@ppc40 study]# sh power.sh whuang4/tmp/abc/dd
rw-
(Note: Indicates that the user Whuang4 has read and write access to the directory/tmp/abc/dd and does not have execute permissions).