Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have to do this in korn because bash is not installed. This is my script so far but it's not quite working as I expect.

cd /
find . -xdev -type d > /tmp/dirlist
export YOURLIST=`cat /tmp/dirlist2`
echo START > /tmp/final
for a in $YOURLIST; do
   export MYLIST=`ll $a | grep "\->" | awk '{print $11;}'`
   echo in dir $a >> /tmp/final
   sleep 5
   for b in $MYLIST; do
      echo `ll $b` 2>&1 > /tmp/result
      grep -q not /tmp/result
      export RC=$?
      if [ "$RC" = "0" ]
      then
         cat /tmp/result >> /tmp/final
      fi
   done
done

Currently it is only printing directories to /tmp/final and it's still displaying not found messages to stdout strangely enough.

share|improve this question

2 Answers 2

find should be able to find symlinks, you don't have to fall back on parsing ls.

find / -xdev -type l -print |
while IFS= read -r f; do
    target=$(readlink "$f")
    [[ -e "$target" ]] || echo "broken symlink: $f -> $target"
done
share|improve this answer
    
readlink not found... but i get the gist of it –  ojblass Jul 8 '13 at 17:05
    
what's your OS? –  glenn jackman Jul 8 '13 at 17:08
    
Nearly everyone ever made including NCR. –  ojblass Jul 8 '13 at 17:15
up vote 0 down vote accepted

Did a two fold thing to simulate what was missing in glenn's response

root@system:/ $ cat /bin/checklink
export ORIGINAL=`ll $1 | awk '{print $9;}'`
export ORIGINALDIR=`dirname $ORIGINAL`
export LINKIS=`ll $1 | awk '{print $11;}'`
export FOUND="0"
if [ -d ${ORIGINALDIR}/${LINKIS} ]
then
     export FOUND="1"
else if [ -f ${ORIGINALDIR}/${LINKIS} ]
     then
       export FOUND="2"
     else if [ -d ${LINKIS} ]
        then
           export FOUND="3"
        else if [ -f ${LINKIS} ]
             then
                export FOUND="4"
             fi
        fi
     fi
fi
if [ "$FOUND" = "0" ]
then
   echo $1 pointing to $LINKIS not found
fi

Followed by a call to

`find / -xdev -type l -exec checklink {} \;

Feel free to improve...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.