这个脚本做什么?

时间:2010-10-21 20:38:54

标签: linux bash

#!/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 个答案:

答案 0 :(得分: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

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