简体   繁体   English

如果特定用户无法写入目录,则 Linux shell 脚本会检查目录

[英]Linux shell script check in an directory if directories are not writeable by specific user

I'm trying to make a Linux shell script with find one or more director(y)ies which are not writeable by a specific user (envadmin).我正在尝试使用查找一个或多个特定用户(envadmin)不可写的导演(y)来制作 Linux shell 脚本。

I think I have to combine these two parts:我想我必须将这两部分结合起来:

# Part 1 - this not complete right because I need if not true that the dir is not writeable and the owner is envadmin:
find -type d -maxdepth 1 ! -writable -user envadmin # I know, this is not working by '! - writable'

# Part 2 - at the if I should need part 1 I think:
for directory in *
do 
    if [ $directory -user envadmin ] ; then
        if [ ! -w $directory ] ; then
            echo "De directory: $directory is from envadmin but not writeable"
        fi
    fi
done

I have tried more but I hope that I have explained it right what I want and I hope that someone can put me in the right direction.我已经尝试了更多,但我希望我已经正确地解释了我想要的东西,我希望有人能把我放在正确的方向上。

You actually don't need any complex scripting for that:您实际上不需要任何复杂的脚本:

find -maxdepth 1 -type d -user eventadmin -and -not -writable

This should give you the desired output.这应该为您提供所需的输出。

Yesterday evening I have found the solution which is working for me I think:昨天晚上,我找到了对我有用的解决方案,我认为:

for directory in  `cd /tmp;find . type -d -maxdepth 1 -user envadmin`; do 
    if [ ! -w $directory ] ; then
        echo "De directory: $directory is from envadmin but not writeable"
        exit 1;
    fi
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM