determining actual directory of a symlinked directory

Hello all,
I have files at /var/dir1/dir2/fil1.log etc.,.

dir2 is symlinked to /export/xxx/dir3

I am trying to monitor the disk space of the mount where these log files are present.
How do I determine dynamically the actual directory of the log files and corresponding mount when I use df command.

Thanks,
Chiru

Some platforms provide a "readlink" program.

If the platform doesn't, it would be simple to write a readlink C program, there is an API function called readlink.

Alternatively, find the inode and volume of the file and attempt to match that way.

The following is a fairly simple little "readlink" shell script using the find command:

#!/bin/sh
LINK="$1"
until [ -z "$LINK" ]; do
    cd $(dirname "$LINK");
     LAST="$LINK"
     LINK=$(find "$LINK" -maxdepth 0 -printf "%l")
    [ "$LAST" != "$LINK" ] || { echo "Looped Links detected!" >&2 ; exit 1; }
    done
echo $LAST

I won't promise that there isn't some sort of degenerate chain of links on which this would choke. But it works in my tests. I should probably also have put in
a maximum number of links to follow (in case following the look with a
system call such as open would return "-ELOOP").

I'll leave that as an exercise to the student.

JimD (former Linux Gazette AnswerGuy

Thanks guys, I got a direction in implementing this from your responses.

I am seeing one issue.

There is a symlink within a symlinked directory which has to be determined dynamically. For example say -
/var/dir1/dir2 is symlinked to /export/xxx/yyy/dir3
and in turn /export/xxx/yyy is symlinked to /opt/zzz
In some places /export/xxx is symlinked to /opt/zzz

My aim is to determine dynamically the path of var/dir1/dir2 and get the result as /opt/zzz/dir2

I'm burning my head to put a script to recursively check all the directories, but going long and long.

Please advise.

Thanks,
Chiru