【shell脚本练习】判断目录读写权限

学习shell小练习

判断/tmp/lzz 这个目录是否有读写权限,如果没有则添加权限


#!/bin/bash
#name: testdir.sh
#authro: orangleliu
#date: 2014-08-03
#version: v1.0
#===================
TestDir="/tmp/lzz"
#===================
#function -> Chenck_Dir()
#===================
Check_Dir()
{
if [ -d "$TestDir" ]
then
    TW=`ls -ld /tmp/lzz/|awk '{print $1}'|sed 's/d//g'|grep 'w'|wc -l`
    TR=`ls -ld /tmp/lzz/|awk '{print $1}'|sed 's/d//g'|grep 'r'|wc -l`
    if [ "$TW" -ne 0 -a "$TR" -ne 0 ]
    then
        echo "$TestDir can writted and readed !"
    else
        echo "$TestDir can not writted and readed !"
        echo -n "Do you add write and rend authority [Y|N]"
        read tt
        case $tt in
            Y|y)
            chmod 755 $TestDir
                if [ $? -eq 0 ]
                then
                    echo "add write and read authority ok ...."
                else
                    echo "add write add read authority fail...."
                    return 1
                fi
            ;;
            N|n)
                return 1
            ;;
            *)
                echo "error"
                return 1
            ;;
        esac
    fi
else
    echo "not have this dir"
    return 1
fi
}

#======================
#function -> Main()
#=====================
Main()
{
Check_Dir
    if [ $? -eq 1 ]
    then
    exit 1
    fi
}

Main

本文出自  orangleliu笔记本  博客,请务必保留此出处 http://blog.csdn.net/orangleliu/article/details/38367237

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值