1837971 Members
3509 Online
110124 Solutions
New Discussion

Script problem

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Script problem

HI,
I have a script written below which loops through a list of machines and creates a symbolic pointing to a filesystem:

I'd like to have the link as:
#ln -s /pgfs1/disk88 /prj/pscx/psc/disks/disks88

Note that psc in /prj/pscx/psc/disks/disks88 is also a symbolic link pointing to /prj/pscx,
hence a pointer to itself i.e /prj/pscx
i.e:
cd /prj/pscx
ln -s . psc

On some machines, /prj/pscx or /prj does not exist.

!#/bin/sh
for i in 'cat machine_list'
do
if [ ! -d /prj ];then
mkdir /prj
cd prj
mkdir /prj/pscx
fi
cd /prj
if [ ! -d /prj/pscx ];then
mkdir /prj/pscx/
fi
cd /prj/pscx
if [ ! -L /prj/pscx/psc];then
ln -s /prj/pscx/ /prj/pscx/psc
fi
cd /prj/pscx/psc
if [ ! -d /prj/pscx/psc/disks ];then
mkdir /prj/pscx/psc/disks
cd disks
if [ ! - L /prj/pscx/psc/disks/disk88 ];then
ln -s /pgfs1/disk88 /prj/pscx/psc/disks/disk88
fi
fi
done

However, it does not create the symbolic link /prj/pscx/psc/disks/disk88. It only creates until /prj/pscx/psc/disks.

Moreover, how do I get the directory /prj/pscx/psc/disks to be created under /prj/pscx/psc, which is only a link? (Don't ask what this link is for - user's request which cannot be refused)

Currently, it only creates /prj/pscx/psc/disks under /prj/pscx as /prj/pscx/psc points to itself i.e /prj/pscx/psc.

Could someone kindly help me out? Or show me how the script should have been done properly?

thanks



3 REPLIES 3
Christian Gebhardt
Honored Contributor
Solution

Re: Script problem

Hi

In your script are some syntax errors, e.g. in the first line
!#/bin/sh has to be
#!/bin/sh

The following script works and it creates the symbolik link /prj/pscx/psc/disks/disk88

#!/bin/sh
for i in `cat machine_list`
do
if [ ! -d /prj ];then
mkdir /prj
cd /prj
mkdir /prj/pscx
fi
cd /prj
if [ ! -d /prj/pscx ];then
mkdir /prj/pscx/
fi
cd /prj/pscx
if [ ! -L /prj/pscx/psc ];then
ln -s /prj/pscx/ /prj/pscx/psc
fi
cd /prj/pscx/psc
if [ ! -d /prj/pscx/psc/disks ];then
mkdir /prj/pscx/psc/disks
cd disks
if [ ! -L /prj/pscx/psc/disks/disk88 ];then
ln -s /pgfs1/disk88 /prj/pscx/psc/disks/disk88
fi
fi
done

Try it and let me know if this script does the job.

Chris
Ian Dennison_1
Honored Contributor

Re: Script problem

the existence entry for the directory including 'disk88' has a space between the - and the L.

The previous occurence of a "-L" test has no space between these.

Try it and see.

Share and Enjoy! Ian
Building a dumber user
John Poff
Honored Contributor

Re: Script problem

if [ ! -d /prj/pscx ];then
mkdir -p /prj/pscx/
fi
cd /prj/pscx
if [ ! -L /prj/pscx/psc ];then
ln -s /prj/pscx/ /prj/pscx/psc
fi
cd /prj/pscx/psc
if [ ! -d /prj/pscx/psc/disks ];then
mkdir /prj/pscx/psc/disks
cd disks
if [ ! -L /prj/pscx/psc/disks/disk88 ];then
ln -s /pgfs1/disk88 /prj/pscx/psc/disks/disk88
else
fi
fi