Sponsored Content
Top Forums Shell Programming and Scripting determining actual directory of a symlinked directory Post 302137392 by AnswerGuy on Monday 24th of September 2007 06:02:30 PM
Old 09-24-2007
Lightbulb Shell script to readlink

Quote:
Originally Posted by chiru_h
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
The following is a fairly simple little "readlink" shell script using the find command:

Code:
#!/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
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Determining directory path

Hello, I have a script where I get the full directory path of the script being executed: BASE=$0 echo "BASE:" $BASE The output looks like this: BASE: /webapps/appsdev/ACURA/rlz/oses3.sh I'd like to truncate the shell name, leaving just the directory path. The directory path can be... (2 Replies)
Discussion started by: cwalsek
2 Replies

2. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

3. Shell Programming and Scripting

Automatically determining directory path for scripts and programs

I have some C++ code in the following directory structure /home/chrisd/tatsh/trunk/hstmy/ ├── baseLib ├── bin │ ├── awk │ ├── bash │ ├── diag │ ├── ksh │ │ └── TAG201011 │ ├── old │ ├── perl │ ├── prog │ ├── py │ └── tcsh ├── docs ├── fortran ├── others... (0 Replies)
Discussion started by: kristinu
0 Replies

4. Shell Programming and Scripting

Catching the xml tag when only parent directory is known ..not the actual directory

Hi folks, I have an query that is let say i have to search in an xml file an tag that is <abcdef> now this xml file is at /opt/usr/local so one fastest way to achieve this is go to this location by cd /opt/usr/local and then do grep like this... grep -i abcdef but for this I must know the... (4 Replies)
Discussion started by: punpun66
4 Replies

5. Web Development

Directory index forbidden by Options directive error on specific directory with indexing disabled

I am seeing the following error appear numerous times in my Apache error log: I have my Apache config configured as below, so I would expect indexing not to occur on this directory as it falls under the parent /web directory. Strangely all the IP address, including this example, all... (5 Replies)
Discussion started by: crmpicco
5 Replies

6. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

7. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

8. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

9. Shell Programming and Scripting

Zipping contents without the actual directory

Hi , I want to zip files present in the directories listed under a parent directory without zipping the directory itself my parent directory path is /informatica/DGDMN/PowerCenter1011/server/infa_shared/SrcFiles/OTE/Final_Directory I have the below directories named as 1,2,3,4,5 listed... (9 Replies)
Discussion started by: paul1234
9 Replies
dircmp(1)						      General Commands Manual							 dircmp(1)

NAME
dircmp - directory comparison SYNOPSIS
n] dir1 dir2 DESCRIPTION
examines dir1 and dir2 and generates various tabulated information about the contents of the directories. Sorted listings of files that are unique to each directory are generated for all the options. If no option is entered, a sorted list is output indicating whether the filenames common to both directories have the same contents. Compare the contents of files with the same name in both directories and output a list telling what must be changed in the two files to bring them into agreement. The list format is described in diff(1). Suppress messages about identical files. Change the width of the output line to n characters. The default width is 72. EXTERNAL INFLUENCES
Environment Variables LC_COLLATE determines the order in which the output is sorted. If is not specified in the environment or is set to the empty string, the value of is used as a default. If is not specified or is set to the empty string, a default of ``C'' (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to ``C'' (see environ(5)). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES
Compare the two directories and and produce a list of changes that would make the directories identical: WARNINGS
This command is likely to be withdrawn from X/Open standards. Applications using this command might not be portable to other vendors' sys- tems. As an alternative is recommended. SEE ALSO
cmp(1), diff(1). STANDARDS CONFORMANCE
dircmp(1)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy