Unix shell scriptto chnage permission

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Unix shell scriptto chnage permission

Miki
#!/bin/bash

# Setting the Variables for execution
LOGDIR=$HOME
CURRENTTIME=$(date +"%Y%m%d%s%H%M%S")
LOGFILE=${LOGDIR}/chgpermission_${CURRENTTIME}.log
MASTERFILE=$1
INDEX=0

# Checking the number of Parameters passed
if [ "$#" -ne 1 ]; then
   echo "Master file name is mandatory parameter" > ${LOGFILE}
   exit 1
fi

# Loading the Master file into an Array
echo "Loading the Master file ${MASTERFILE} into an array" >> ${LOGFILE}
while read line
do
#echo $line  
MASTERARRAY[$INDEX]=$HOME/$line
INDEX=$(expr $INDEX + 1)
done < ${MASTERFILE}

echo "Number of parameters in an master array ${MASTERARRAY[@]}" >> ${LOGFILE}

# Changing the permission of the file
echo "Changing the permission of the file in master file ${MASTERFILE}" >> ${LOGFILE}
index=0
for index in "${MASTERARRAY[@]}"
do
   if [ -f "$index" ]
   then
      echo "$index file exist"
      echo  "$index file exist" >> ${LOGFILE}
      chmod 755 "$index"
      chown workstation "$index"
      chgrp workstation "$index"
   else
     echo "$index file does not extst"
     echo "$index file does not exist" >> ${LOGFILE}  
   fi
done