2010-10-21 90 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 

请,对不起,如果我不应该回答这个问题......如果这是错的,请删除它,并提醒我不要再这样做。