2010-10-21 88 views
0
#!/bin/bash 
RYD=/share 
FILESPEC=*.sh 
DIRPERM=700 
FILEPERM=750 
OWNER=user:group 
CH_FSPEC=0 
if [ -d $RYD ]; then 
    find $RYD -type d | xargs chmod $DIRPERM 
    if [ $CH_FSPEC -gt 0 ]; then 
    find $RYD -type f | xargs chmod $FILEPERM 
    else 
    find $RYD -type f | grep -v "$FILESPEC" | xargs chmod $FILEPERM 
    fi 
    chown -R $OWNER $RYD 
    for SCRIPT in $RYD/$FILESPEC; do 
    if [ -x $SCRIPT ]; then 
     echo "Executing : $SCRIPT" 
     . $SCRIPT 
    fi 
    done 
else 
    echo "ERROR! The directory doesn't exist." 
    exit 1 
fi 
exit 0 
+1

家庭作業問題。 – 2010-10-21 20:51:04

+1

它不會做任何寫它的人認爲它會做的;它正在爬蟲。 – zwol 2010-10-21 20:56:33

+2

它似乎試圖運行/ share及其子文件夾中找到的所有內容。這不好。 – 2010-10-21 21:00:56

回答

0

我不知道回答這類問題是否有好處,因爲它是作業......但我看到其他問題被標記爲家庭作業已回答,所以我們走了。

#!/bin/bash 
RYD=/share 
FILESPEC=*.sh 
DIRPERM=700 
FILEPERM=750 
OWNER=user:group 
CH_FSPEC=0 
if [ -d $RYD ]; then # If $RYD is a directory 
    find $RYD -type d | xargs chmod $DIRPERM # Look for all subdirectories and chmod them with $DIRPERM 
    if [ $CH_FSPEC -gt 0 ]; then # if $CH_FSPEC > 0 
    find $RYD -type f | xargs chmod $FILEPERM # find all files inside $RYD and chmod them with $FILEPERM 
    else # if $CH_FSPEC <= 0 
    find $RYD -type f | grep -v "$FILESPEC" | xargs chmod $FILEPERM # find all files inside $RYD, ommit *.sh files and chmod them with $FILEPERM 
    fi 
    chown -R $OWNER $RYD # chown $RYD with $OWNER 
    for SCRIPT in $RYD/$FILESPEC; do # loop *.sh files inside $RYD 
    if [ -x $SCRIPT ]; then # if they have exec perm 
     echo "Executing : $SCRIPT" # run it 
     . $SCRIPT 
    fi 
    done 
else # if $RYD does not exist or isnt a directory 
    echo "ERROR! The directory doesn't exist." 
    exit 1 
fi 
exit 0 

請,對不起,如果我不應該回答這個問題......如果這是錯的,請刪除它,並提醒我不要再這樣做。