Sponsored Content
Top Forums Shell Programming and Scripting ksh Script to Generate Symbolic Links Post 302072906 by dwisconbug on Monday 8th of May 2006 06:37:51 PM
Old 05-08-2006
ksh Script to Generate Symbolic Links

I'm writing a ksh script which will reference a text file I have to create symbolic links for my application:

--file contents--
Link Directory Link Source Link Name
/users/05/dwisconbug bin link2bin


Now, this should create the following link

link2bin -> /users/05/dwisconbug/bin

Before the script creates the symbolic link "link2bin" it needs to see if the link already exists - I know with brute force i can just delete the current link and recreate it, but I want to make sure the current link is pointing to the right source.

How do I use ksh/Unix commands to:

1) "ls -l link2bin" and awk(?) to grab the "link2bin-> /users/05/dwisconbug/bin"

2) If I set the contents of my file to the variables $link_dir, $link_src, and $link_nm generate what I expect the link to look like

3) somehow diff the results from steps #1 and steps #2 to make sure the existing link matches what I have listed in my file?

Any ideas? Thanks in advance!

PS: as you can imagine I need to get this working by the end of the day - so any help is appreciated!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding symbolic links

How can I find all symbolic links across the network to a directory (2 Replies)
Discussion started by: mehtad
2 Replies

2. Solaris

cp a dty without symbolic links?

Hi, - we have copy (cp command) to do to save all the contents of a dty BUT we dont want to copy the files corresponding to symbolic links contained whithin this dty - the box is a sun solaris one - and the cp commande do not say avything about that? thanks for help Jakez (7 Replies)
Discussion started by: JAKEZ
7 Replies

3. AIX

Symbolic Links

I am linking a directory as follows: ln -sf /home/xxx/userid/real_files/* /home/xxx/userid/linked_files This gives me symbolic links for all the files in the real_files directory in the linked_files directory. My question is, if I go and remove a file in the real_files directory and then go... (1 Reply)
Discussion started by: rcarnesiii
1 Replies

4. Shell Programming and Scripting

Symbolic Links - BASH Script

Hi all, This is my first message in this forum. I'd like to know if there is a nice way to get the complete path from a symbolic link. Example: When I do a ls -ltr I see this output. lrwxr-xr-x 1 mmmm users 66 Sep 4 09:58 LINK_SEND ->... (4 Replies)
Discussion started by: rodrimuino
4 Replies

5. Solaris

symbolic links between servers

Hi Guys... I want to create a link using ln -s for a directory that does not exist on the box. How do I do that? I had some files from Box A directory /d1/u01 and I copied the files across to another Box lets say Box B on directory /d2/u02. Now I want a link so that this path /d1/u01... (2 Replies)
Discussion started by: Phuti
2 Replies

6. UNIX for Dummies Questions & Answers

Symbolic Links

Hi all, I have scoured the entire forum for this but to no avail unfortunately. Basically, I would like to remove my symbolic link from my folder name i.e. foldername -> /a/b/c/d/f where f is indeed a folder. I have tried rmdir but this does not work and in actual fact deletes the... (4 Replies)
Discussion started by: cyberfrog
4 Replies

7. Shell Programming and Scripting

How to change symbolic links via script

Hello, the install routine puts automatically the servername "SERVER" in the symlink like: hello.txt --> /SERVER/usr/lpp/hello.txt world.txt --> /SERVER/usr/lpp/world.txt ... but i need to change this symlinks (without servername) to: hello.txt --> /usr/lpp/hello.txt world.txt -->... (3 Replies)
Discussion started by: smitty11
3 Replies

8. UNIX for Dummies Questions & Answers

Symbolic links in UNIX

Hi, I have a file with more than 1 layers of soft links for it. For ex. ls -la .profile .profile@ -> /home/act/.profile_abc ls -la /home/act/.profile_abc@ -> .profile_final I want to get the name of the last file (i.e. .profile_final) when I refer to .profile using shell script. I... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

9. Solaris

Symbolic links

Soft link,Hard link brief explanation (1 Reply)
Discussion started by: RAJU KAVATI
1 Replies

10. Shell Programming and Scripting

Script for creating symbolic links to my photos (*.JPG)

Hi, I have all my pictures as *.JPG and *.CR2 in the following folder structure: /media/a_2TB/pictures/year/year-month-day-hour/picture*.* But sometimes I added a subdirectory --> /media/a_2TB/pictures/year/year-month-day-hour/suba/picture*.*... (3 Replies)
Discussion started by: 8200
3 Replies
LN(1)							      General Commands Manual							     LN(1)

NAME
ln - make links SYNOPSIS
ln [ -s ] sourcename [ targetname ] ln [ -s ] sourcename1 sourcename2 [ sourcename3 ... ] targetdirectory DESCRIPTION
A link is a directory entry referring to a file; the same file (together with its size, all its protection information, etc.) may have several links to it. There are two kinds of links: hard links and symbolic links. By default ln makes hard links. A hard link to a file is indistinguishable from the original directory entry; any changes to a file are effective independent of the name used to reference the file. Hard links may not span file systems and may not refer to directories. The -s option causes ln to create symbolic links. A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open(2) operation is performed on the link. A stat(2) on a symbolic link will return the linked-to file; an lstat(2) must be done to obtain information about the link. The readlink(2) call may be used to read the contents of a symbolic link. Symbolic links may span file systems and may refer to directories. Given one or two arguments, ln creates a link to an existing file sourcename. If targetname is given, the link has that name; targetname may also be a directory in which to place the link; otherwise it is placed in the current directory. If only the directory is specified, the link will be made to the last component of sourcename. Given more than two arguments, ln makes links in targetdirectory to all the named source files. The links made will have the same name as the files being linked to. SEE ALSO
rm(1), cp(1), mv(1), link(2), readlink(2), stat(2), symlink(2) 4th Berkeley Distribution April 10, 1986 LN(1)
All times are GMT -4. The time now is 09:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy