#!/bin/bash # $Id: chklnks,v 1.142 2023/06/16 17:15:35 fulford Exp fulford $ # $Source: /src/admin/usr/local/etc/RCS/chklnks,v $ # $Revision: 1.142 $ # Author C W Fulford. # Copyright 2014 (c) C W Fulford. # Licensed for public use under the LGPL, . # For assistance contact fulford@fulford.net 0709 229 5385 ######################################################################## cmd=`basename $0` syntax="$cmd [-d] [[-h <hostid> [-r] [-v] [[-a]|[<dir_name> <dir_name> ...] -x <dir_name ]]|[-V]" while [ $# -gt 0 ] ;do case $1 in -a) all=0;shift;; -d) set -x;debug=:;shift;; -h) hostid=$2;shift 2;; -r) action=delete;shift;; -v) verbose=0;shift;; -V) echo "$cmd $Revision: 1.142 $ $Date: 2023/06/16 17:15:35 $"|awk '{print $1,$3,$6}';exit;; -x) xdirs="$xdirs $1";shift 2;; /*) paths="$paths $1";shift;; *) echo "$syntax" >&2;exit;; esac done action=${action:-"echo"} all=${all:=1} [ $all -eq 0 -a "$paths" ] &&{ echo "$cmd: can't specify directories with the -a option" >&2 echo "syntax: $syntax" >&2 exit 1 } tmounts=/tmp/mounts-$$ targets=/tmp/targets-$$;>$targets verbose=${verbose:-1} if [ "$hostid" ]; then if nc -zw 2 $hostid 22 ;then rchk="ssh $hostid" ssh $hostid "sudo cat /etc/mtab" >$tmounts else echo "$cmd: ssh not available on $hostid" >&2 exit 1 fi else cat /etc/mtab >$tmounts fi if [ $all -ne 0 ];then cat $tmounts| awk '{ print $2 }' #egrep -v "/proc||^nfsd|gvfsd-fuse|sysfs|$xdirs" | fi echo $paths ;exit paths=${paths:-"./"} [ "$verbose" -eq 0 ] &&{ echo "$cmd: paths = "$paths } for d in $paths;do if [ $verbose -eq 0 ];then echo "$cmd: checking directory $d" fi $rchk sudo find -P $d -xdev -type l -print >>$targets awk '{printf $1}' $targets |while read f ;do if [ $action == "delete" ] ;then $rchk "sudo rm $f" if [ $? -eq 0 -a $verbose -eq 0 ];then echo "$cmd: $f dead link removed" >&2 fi else $action "$cmd: found dead link $r" >&2 fi done done if [ $debug ] ;then cat $tmounts $targets else echo $tmounts $targets #sudo rm $tmounts $targets fi ###################################################################### # This program is free software: you can redistribute it and or # # modify it under the terms of the Lesser GNU General Public License # # as published by the Free Software Foundation, either version 3 of # # the License, or (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # A copy of the Lesser GNU General Public License and the GNU # # General Public License is available at # # <http://www.gnu.org/licenses/>. # ######################################################################
Copyright
© 2003-2017
Clifford W Fulford.
Fulford Consulting Ltd.
Regd. Co. 4250037 in England & Wales.
Regd. office 162, Edward Rd. Nottingham NG2 5GF, England, UK.
Related web sites: City Linux | Flare Support | West Bridgford | Fulford Portal | Joan Mary Fulford (Nottingham Writer) | Fulford Gallery | Amharic Interpreter | Arabic Interpreter | Tigrinya Interpreter
The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.