How Linux determines how the specified user's permissions on the specified directory are specifically described

Source: Internet
Author: User

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).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.