首页 > 解决方案 > 如果特定用户无法写入目录,则 Linux shell 脚本会检查目录

问题描述

我正在尝试制作一个 Linux shell 脚本,找到一个或多个特定用户(envadmin)不可写的director(y)ies。

我想我必须将这两个部分结合起来:

# 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

我已经尝试了更多,但我希望我已经正确地解释了我想要的,我希望有人能把我引向正确的方向。

标签: linuxshell

解决方案


您实际上不需要任何复杂的脚本:

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

这应该会给你想要的输出。


推荐阅读