[Shell]判斷目錄讀寫權限

來源:互聯網
上載者:User

標籤: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    fielse    echo "not have this dir"    return 1fi}#======================#function -> Main()#=====================Main(){Check_Dir    if [ $? -eq 1 ]    then    exit 1    fi}Main

本文出自 “orangleliu筆記本” 部落格,請務必保留此出處 http://blog.csdn.net/orangleliu/article/details/38367237

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.