记录一次检查权限的小工具

check-exec.sh

#! /bin/bash

function read_dir(){
	for file in `ls $1`
	do
		
		if [ -d $1"/"$file ]
		then
			read_dir $1"/"$file
		else
			file "${1}/${file}" | grep -q 'text'
			retval=$?
			if [ $retval -eq 0 -a  -x "${1}/${file}" ]; then
#				echo $1"/"$file  >>xfile.txt
			    res=`echo $1"/"$file | sed 's/^.*'$dirPathname'//g'`
			    if [ -f exec-list.txt ]; then
				    rm exec-list.txt
			    fi
			    echo ${res#*/} >> exec-list.txt
			   
			else
				echo $1"/"$file "no" 
			fi
		fi
	done
}

path1=`pwd`
path2=${path1%/*}
path3=${path2%/*}
path=${path3%/*}
dirPathname=${path##*/}
echo $dirPathname
read_dir $path 

restore-exec.sh

#!/bin/bash


path1=`pwd`
path2=${path1%/*}
path3=${path2%/*}
path=${path3%/*}
#echo $path
while read line;do
#	echo $path"/"$line	
	if [ ! -x $path"/"$line ]; then
		finalpath1=$path"/"$line
		finalpath=${finalpath1%/*}
		resfile=${finalpath1##*/}
		find $finalpath -name $resfile | xargs chmod 755
		echo $resfile "yes 已修复权限" 	
	fi
	

done < exec-list.txt


check-softlink.sh

#!/bin/bash

path1=`pwd`
path2=${path1%/*}
path3=${path2%/*}
path=${path3%/*}
dirPathname=${path##*/}

if [ -f softlink-list.txt ]; then
	rm softlink-list.txt
fi

find $path -maxdepth 20 -type l | xargs ls -l | awk '{for(i=1;i<=8;i++){$i=""};print $0}' | sed 's/^\s*//g' | sed 's/^.*'$dirPathname'//g' | sed 's/^\///g' >> softlink-list.txt

#while read line; do
#	 `${line#*/}` >> softlink-list.txt
#done < softlink-list.txt

restore-softlink.sh

#!/bin/bash

path1=`pwd`
path2=${path1%/*}
path3=${path2%/*}
path=${path3%/*}


while read i; do
	
        softlink1=`echo $i | awk '{print $1}'`  #软链接路径
	softlink2=$path"/"$softlink1   #实际的软链接路径
  	softlink=${softlink2%/*}    #软链接目录名
	#echo $softlink
	softname=$(basename $softlink2)  #软链接名字
	
        #-----------处理软链接路径 end------------------------------------# 
	

        #-----------处理源文件路径 start----------------------------------# 
	srcpath=`echo $i | awk '{print $3}'`
#	echo $srcpath
	echo $softlink
	cd $softlink
	if [ -f $softname ]; then
		if [ -h $softname ]; then
			echo $softname "软链接已存在"
		else
			rm $softname
		fi
	else
		ln -s $srcpath $softname
		
	fi
	echo $softname "yes 已修复" >> modifysoft.txt
#       if [[ $srcpath1 == ..* ]]; then
#		srcfile1=${softlink%/*}
#		srcfile2=${srcfile1%/*}  #源文件路径的上一级目录
#		srcfile3=${srcpath1#*/}
#		srcfile=$srcfile2"/"$srcfile3  #处理的源文件路径
#	else
#		srcfile1=${softlink%/*}
#		srcfile=$srcfile1"/"$srcpath1  #如果同级目录下

#	fi
       # echo $srcfile
        #-----------处理源文件路径 end------------------------------------#

	
        #-----------处理是否为软链接 并修复 start------------------------#
	
#	resfile=${softlink##*/}
#	ln -s $srcfile $softlink
#	echo $resfile "yes 已修复软链接" >> modifysoft.txt
done < softlink-list.txt



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

z666666y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值