(1)、检验目录权限

#!/bin/bash

test="/tmp/aa"
check_direc()
{
    if [ -d "test" ];then
    tw = `ll -ld /tmp/aa | awk '{print $1}' | sed 's/d//g' | grep "w" | wc -l`
    tr = `ll -ld /tmp/aa | awk '{print $1}' | sed 's/d//g' | grep "r" | wc -l`
    if [ "$tw" -ne 0 && "$tr" -ne 0 ];then
        echo "$test have write and read"
    else
        echo "$test have not write and read"
        echo "do you want to write and read [Y|N]"
        read qq
        case $qq in
        Y|y)
        chmod 755 $test
            if [ $? -eq 0 ];then
            echo "add write and read ok..."
            else
            echo "add write and read fail..."
            return 1
            fi
        ;;
        
        N|n)
            return 1
        ;;
        
        *)
            echo "error"
        ;;
        esac
    fi
    else
    echo "have not $test"
    return 1
    fi

#===============
#Function-->Main
#===============

main()
{
    check_direc
    if [ $? -eq 1 ];then
    exit 1
    fi
}

main

你可能感兴趣的:((1)、检验目录权限)