how to check links exists proper or not in solaris 10


 
Thread Tools Search this Thread
Operating Systems Solaris how to check links exists proper or not in solaris 10
# 1  
Old 04-26-2012
how to check links exists proper or not in solaris 10

Hi,
I am using solaris 10 OS and Bash shell.I am looking for the command to check whether link is exits or not.if not i have to create it
Requirement here is say in the server1 i have a directory /spa/5.0.in that directory there are so many links exist.

Example links:
genver -> sa0_genver_releasegenlibs -> sa0_genlibsscripts -> /spa/common/5.0/scriptsfiletran -> /spa/common/5.0/filetrandata -> /spa/common/5.0/dataI have tried following command to find out the links are exist or not.

Code:
ls -lrt|grep machdefs.pl |grep ^llrwxrwxrwx   1 spal     spastaff      11 Apr 10 16:59 AUX_MACHINE_DEFINITION -> machdefs.pl

but i don't know how to find out if the links does not exist or broken.

My Aim here is need to check for the links,if it doesnot exist or broken i need to create the link in a automated script.I am checking for the command to verify it later on i will automate this through scripting.

Appreciate your help on it. Smilie

---------- Post updated at 02:05 AM ---------- Previous update was at 12:06 AM ----------

I have tried with readlink() but no luck. Any help on it?

Last edited by DukeNuke2; 04-26-2012 at 02:21 AM..
# 2  
Old 04-26-2012
To know if a symbolic link points to a file or a directory you can simply use the test -f and test -dcommands.

eg:
Code:
file=/some/name
if [ -L $file -a ! -d $file -a ! -f $file ]
then
  echo "$file is a symlink but doesn't point to a regular file or a directory."
fi

ls -lL will also show up dangling links
This User Gave Thanks to jlliagre For This Post:
# 3  
Old 04-26-2012
Broken links have a link count (the 2nd field in ls -ladL) of zero.

Code:
ls -lad abc2
lrwxr-xr-x   1 root       sys              4 Apr 26 16:02 abc2 -> abc1
ls -ladL abc2
----------   0 root       root             0 Jan  1  1970 abc2

This User Gave Thanks to methyl For This Post:
# 4  
Old 04-26-2012
@methyl: on what OS are you observing this fake entry ?

On Solaris 10:

Code:
# ls -l foo
lrwxrwxrwx   1 jlliagre jlliagre       8 Apr 26 17:47 foo -> notfound
# ls -ladL foo
foo: No such file or directory

Gnu/Linux has a similar error:
Code:
# ls -ladL foo
ls: cannot access foo: No such file or directory

# 5  
Old 04-26-2012
methyl - something is not kosher
Code:
jmcnama@SNEDAP03 ~> ls foo
foo: No such file or directory
jmcnama@SNEDAP03 ~> ln -s foo newfoo
jmcnama@SNEDAP03 ~> ls -l newfoo
lrwxrwxrwx   1 jmcnama  other          3 Apr 26 10:42 newfoo -> foo
jmcnama@SNEDAP03 ~> ls -Ll newfoo
newfoo: No such file or directory
jmcnama@SNEDAP03 ~>

jlliagre is correct POSIX behavior for ls -L is to report no file found, when the "destination file" for the link does not exist.
Is that an HPUX feature?
# 6  
Old 04-26-2012
Yes, works on HP-UX 11.11. Never noticed on other Operating Systems because I rarely get problems with soft links.

Wrote a script to use this quite recently after needing to move and rename a filesystem and correct various broken links en masse.

I have a quite different and longer script for finding all links to any file which has links (soft or hard) which detects broken links by more conventional methods. It was unsuitable for my recent purpose until after the repair.
# 7  
Old 04-27-2012
Thanks everyone for your responses.Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if file exists

I need to check whether a file exists and has been changed. The file should contain a specific string. The file should also have been changed within the last ten seconds. How do I do that? (3 Replies)
Discussion started by: locoroco
3 Replies

2. Shell Programming and Scripting

To check if file exists

Hi, I have the below code written. However I am not getting the desired output I am checking if the particular path has file in it. #!/bin/bash ls -l /IRS2/IRS2_ODI/INFILE/*LS* 1>/dev/null 2>/dev/null if then echo $? echo "File Exists" fi ... (3 Replies)
Discussion started by: Shanmugapriya D
3 Replies

3. Shell Programming and Scripting

Check if file exists or not

Hi, I want to check if the file exists or not in the directory. i am trying below code but not working. File="/home/va59657/Account_20090213*.dat" echo "$File" if ]; then echo "file found" else echo "file not found" fi However i am getting file not found even if file exits as... (5 Replies)
Discussion started by: Vivekit82
5 Replies

4. Shell Programming and Scripting

How to check if the URL exists?

Hi, I need to check if the URL exists. Below is my OS: SunOS mymac1 Generic_148888-04 sun4v sparc SUNW,SPARC-Enterprise-T5220 I do not have the curl set in the profile nor am i aware about its path. But i have wget. Please help me with params for the same. Can you help me check if... (6 Replies)
Discussion started by: mohtashims
6 Replies

5. UNIX for Dummies Questions & Answers

How to check if a number exists?

Hello, May i please know how do i check if the given input argument is one of the listed numbers then success else failure. I am using bash shell. if then echo "success" else echo "failure" fi Thank you. (2 Replies)
Discussion started by: Ariean
2 Replies

6. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

7. Shell Programming and Scripting

Need to check links exists in the server based on that need to run the build script

Hi, I am working on a build script which will check for the links existing in the server ,then run the gen command to start the build process. Appreciate help on this. server os:sun solaris 10.Bash shell links present in the server location /spa/5.0: genver -> sa0_genver_release... (1 Reply)
Discussion started by: muraliinfy04
1 Replies

8. UNIX for Dummies Questions & Answers

check file is a proper flv

Hello, On a linux server (centos 5.4), users upload file that should be flv. How can I check that the file is a real and proper flv file? Checking the extension is not enough! Thanks (1 Reply)
Discussion started by: JCR
1 Replies

9. Shell Programming and Scripting

How to check if a direcorty exists?

Hi Good people :D How do I check if a directory exists, if it does then carry on rest of the script, otherwise exit. ------------- cd $mainfolder/system1 #unzips files arrived in last 24 hrs into temp directory find * -mmin -1440 -exec unzip {} \; I'd like to check here if temp... (2 Replies)
Discussion started by: SunnyK
2 Replies

10. Shell Programming and Scripting

Check for proper e mail id format

Hi, We run an application called meta which reads user information from database and updates in LDAP.For that we have some scripts to check the uniqueness of mail ids between the existing LDAP and Database.It works fine when people enter mail ids in proper format (xxx.yyy@abc.com) but if it... (2 Replies)
Discussion started by: prolay
2 Replies
Login or Register to Ask a Question