测试断掉的连接

1 #!/bin/bash
2 # broken-link.sh
3 # 由Lee bigelow所写<ligelowbee@yahoo.com>
4 # 已经征得作者的同意.
5
6 #一个用于发现死符号链接并且输出它们的链接文件的纯shell的脚本。
7 #所以它们能把输出提供给xargs并处理 :)
8 #例如: broken-link.sh /somedir /someotherdir|xargs rm
9 #
10 #下面是更好的发现死符号链接的办法:
11 #
12 #find "somedir" -type l -print0|\
13 #xargs -r0 file|\
14 #grep "broken symbolic"|
15 #sed -e 's/^\|: *broken symbolic.*$/"/g'
16 #
17 #但这不是纯bash脚本,下面的则是.
18 #注意: 谨防在/proc文件系统和死循环链接中使用!
19 ##############################################################
20
21
22 #如果没有参数被传递给脚本作为搜索目录,则使用当前目录
23 #
24 #
25 ####################
26 [ $# -eq 0 ] && directorys=`pwd` || directorys=$@
27
28 #Setup the function linkchk to check the directory it is passed
29 #for files that are links and don't exist, then print them quoted.
30 #If one of the elements in the directory is a subdirectory then
31 #send that send that subdirectory to the linkcheck function.
32 ##########
33 linkchk () {
34 for element in $1/*; do
35 [ -h "$element" -a ! -e "$element" ] && echo \"$element\"
36 [ -d "$element" ] && linkchk $element
37 # Of course, '-h' tests for symbolic link, '-d' for directory.
38 done
39 }
40
41 #Send each arg that was passed to the script to the linkchk function
42 #if it is a valid directoy. If not, then print the error message
43 #and usage info.
44 ################
45 for directory in $directorys; do
46 if [ -d $directory ]
47 then linkchk $directory
48 else
49 echo "$directory is not a directory"
50 echo "Usage: $0 dir1 dir2 ..."
51 fi
52 done
53
54 exit 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值