I used to program ksh a while back, but I've been off in Oracle/Windows land (for clients -- not by choice) for so long that I can't remember what should be an easy thing. Here's the scenario:
1)Find all files and directories beneath some directory point (A).
2)If directory, make the subdirectory at some different directory point (B)
3)If file, link (not symbolic) the file in the correct subdirectory under point B.
For a more concrete example, here's a scenario.
Point A: /usr/test
Point B: /var/test
File structures:
/usr/test
/usr/test/oracle
/usr/test/oracle/script 1
/usr/test/oracle/script 2
/usr/test/db2
/usr/test/db2/script 1
/usr/test/db2/script 2
I'm trying to write a script that will result in the following output (and/or actually do the work instead of writing an output script, but I can live with creating a secondary script):
mkdir /var/test/oracle
ln /usr/test/oracle/"script 1" /var/test/oracle/"script 1"
ln /usr/test/oracle/"script 2" /var/test/oracle/"script 2"
mkdir /var/test/db2
ln /usr/test/db2/"script 1" /var/test/db2/"script 1"
ln /usr/test/db2/"script 2" /var/test/db2/"script 2"
Here's the pseudo code for what I've been working on so far:
#!/bin/bash
#declare variables
cnt=0 #array counter
# &1 == Source Directory
# &2 == Target Directory
source_len=awk '{ print length }'
# Find out what the subdirectories are
full_list=find $1 -print 2>/dev/null
## Populate the subdirectories into an array
## Trim the root from the subdirectories into a second array
subdir = full_list| cut -c source_len-
# Loop through, creating them one at a time.
if [-d full_list]
then
# make the new directory
echo "mkdir $target/$subdir"
elif [-f source]
then
# link the file
echo "ln $full_list $target/$subdir"
fi
Someone suggested to me mounting /usr/test to /var/test, but that doesn't completely satisfy the necessary requirements (and would result in a few thousand mount points being scattered through the environment -- not a pretty picture)...
if this was PL/SQL, it would have taken me about 15 seconds to write, but I'm rusty on bash scripting. Any thoughts?
--CS