Help cannot concatenate Ksh variables ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help cannot concatenate Ksh variables ?
# 29  
Old 02-22-2012
Okay we've got past one very common scripting problem ("for" vs "while").

Back to the Microsoft text file format problem in your data files (imho).
I believe that your display format is all over the place because the input data contains carriage-return characters (or some other weird control codes which do not belong in a unix text file) and you have in places deleted line-feed characters (the standard unix text file line terminator). Therefore I believe that what you are seeing on the screen is only part of the output from your script because the screen driver is actioning these rogue control codes.

Back to an earlier request. We need to see a sample .svn/entries file displayed in a manner where we can see control codes:
For example:
Code:
sed -n l .svn/entries

Also, please post the current version of the script. I can't see anything in the most recent version posted which writes to a file (unless you are referring to a saved file from "script").


We'll come back to the code at the bottom of post #24 if necessary, but I for one can't follow it!

Last edited by methyl; 02-22-2012 at 05:57 PM..
# 30  
Old 02-22-2012
# 31  
Old 02-22-2012
Is that not the same thread as this one?
# 32  
Old 02-22-2012
sorry two webpages open. never used this before
go to #19 console out put shows the output file name
# 33  
Old 02-23-2012
Quote:
OldRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1 | tr -d '\n'`
I suspect that the higlighted file(s) contain control codes which should not be in a unix text file. Most likely carriage-return characters from a Microsoft computer. Post #19 does not show a sample of one of these files.
Just need to confirm this fact by making the control codes visible. This could equally be done with the unix "od" command but that "sed" command is a quick and easy way of seeng the bad characters.
# 34  
Old 02-23-2012
output you requested

Recap:
OK

I sent this output once before the first time I was asked (remember I only grep'ed for the hostURL)

Code:
sed -n l .svn/entries

sample of Subversion metadata output from code above only interested in the hostname
Code:
10$
$
dir$
876$
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/CSInitiation/Comp\
onents/PEIntegration/trunk/ProcessProjectEast$
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/CSInitiation$
$
$
$
2010-07-02T12:42:25.553687Z$
307$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
f5108aaa-e11d-cc89-9689-d28c396b277b$
\f$
ProcessProjectEast.def$
file$
$
$
$
$
2011-02-28T22:07:10.023828Z$
23d07e86b33e7583b7a93c725a5a34ca$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
244$
\f$
MDPHeader.h$
file$
$
$
$
$
2011-02-28T22:07:09.898829Z$
e05219b9140462cdc5504f8ce1694de8$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
1845$
\f$
StdAfx.h$
file$
$
$
$
$
2011-02-28T22:07:09.758206Z$
d6f1a097c34be362029fbf76f8eb8586$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
1116$
\f$
ChapterMacros.h$
file$
$
$
$
$
2011-02-28T22:07:10.148826Z$
1442afeb3c77c7a5221821c8085df00f$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
12937$
\f$
ProcessProjectEast_p.c$
file$
$
$
$
$
2011-02-28T22:07:10.367573Z$
7f2cab3fc9eddbdcec649d554573d4cf$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
10151$
\f$
ProcessProjectEastps.def$
file$
$
$
$
$
2011-02-28T22:07:10.258200Z$
10419b3542ce7f31bc9711fa2973c41e$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
260$
\f$
ReleaseMinDependency$
dir$
\f$
ProcessProjectEast.vcproj$
file$
$
$
$
$
2011-02-28T22:07:10.508196Z$
7f3c6be93c1b6ce7fad29f028bfaa26a$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
21594$
\f$
ProcessProjectEast.rc$
file$
$
$
$
$
2011-02-28T22:07:10.633195Z$
1e096c73f3a457eea88ba668f5f2086e$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
2929$
\f$
dlldata.c$
file$
$
$
$
$
2011-02-28T22:07:10.742568Z$
932bdabf7549426dd17da0ca2938d461$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
857$
\f$
ProcessProjectEast.idl$
file$
$
$
$
$
2011-02-28T22:07:10.867567Z$
3d988f763a601465037c49e53747b672$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
970$
\f$
ProcessProjectEastps.mk$
file$
$
$
$
$
2011-02-28T22:07:10.961316Z$
c1a5142569e47c58da93fcc40126dafb$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
586$
\f$
ProcessProjectEast.dll$
file$
$
$
$
$
2011-02-28T22:07:11.242562Z$
5fb84c2444d1db8c2f2d754679260364$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
has-props$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
126976$
\f$
Distrib$
dir$
\f$
ProcessProjectEast.cpp$
file$
$
$
$
$
2011-02-28T22:07:11.445684Z$
477d9f215c4caaee977d425cb97010b7$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
2028$
\f$
ProcessProjectEast.plg$
file$
$
$
$
$
2011-02-28T22:07:11.570683Z$
4f4c9ff1d32685fd756a026c3d2daf2e$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
4235$
\f$
GetAlliedData.cpp$
file$
$
$
$
$
2011-02-28T22:07:11.726931Z$
9580b0395ef29a10accc56a937884ec7$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
42011$
\f$
BCSHeader.h$
file$
$
$
$
$
2011-02-28T22:07:11.820680Z$
11225e6d976996bd3e910ff431061f5a$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
1423$
\f$
ProcessProjectEast.dsp$
file$
$
$
$
$
2011-02-28T22:07:11.976928Z$
53666778dc1fbbb36d3bd645f71dff3c$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
13575$
\f$
StdString.h$
file$
$
$
$
$
2011-02-28T22:07:12.164425Z$
e940af01835a781d0fb5c83a93f31161$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
140311$
\f$
ProcessProjectEast.h$
file$
$
$
$
$
2011-02-28T22:07:12.273799Z$
a93bc5fa8f1a3cec7d91b16d8acaa125$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
7217$
\f$
chapters$
dir$
\f$
GetAlliedData.h$
file$
$
$
$
$
2011-02-28T22:07:12.414422Z$
0905f0fe31ecb1005a2c02388a495f66$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
5218$
\f$
StdAfx.cpp$
file$
$
$
$
$
2011-02-28T22:07:12.539420Z$
31ecfd2ed01585b8c3d387a5b74ae675$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
410$
\f$
ProcessProjectEast_i.c$
file$
$
$
$
$
2011-02-28T22:07:12.648794Z$
1586aac1b401d80eac8abc12cfa2afc1$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
2066$
\f$
ProcessProjectEast.sln$
file$
$
$
$
$
2011-02-28T22:07:12.758168Z$
462a8e7f10b5004473a97a308facd1da$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
2324$
\f$
resource.h$
file$
$
$
$
$
2011-02-28T22:07:12.867541Z$
b1af78ada6d2c444253e65acf3edf813$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
511$
\f$
ProcessProjectEast.dsw$
file$
$
$
$
$
2011-02-28T22:07:13.008164Z$
aac1152a8a3b6c04cafe07c75d08f91e$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
679$
\f$
GetAlliedData.rgs$
file$
$
$
$
$
2011-02-28T22:07:13.148788Z$
28f6ffae3d773343d482de52d5b029d5$
2010-06-14T19:37:38.335734Z$
216$
demmond1$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
717$
\f$

Environment:
All directories used were copied from a Windows Server to a Linux Server to extract the data for the script I am trying to build, I do not know DOS so I thought I could use ksh scripting to create the script for the mass relocation of the Subversion Working Copies (WC). The only way to differentiate a directory that contains a Subversion WC ( a directory that contains data checked out from Subverion) is that the directory contains a .svn(dotsvn) directory.

The .svn(dotsvn) directory contains a file "entries", the "entries" file contains metadata for the WC , it (entries) contains the URL to the host where the repository is located that contains the data that was checked out and copied to the WC directory.

Relocation - The server that contains the Subversion Repositories (OldRepo) from which the WC came has been migrated to another server along with the Repositories (NewRepo).

What needs to happen is the Subversion relocate command (svn relocate) needs to be executed in each directory that contains the .svn(dotsvn) directory.
the command string is
Code:
"svn relocate OldRepoURL NewRepoURL"

In order to create the "final script" the following is required:

1) Make a list of all the directories that contain the .svn(dotsvn) subdirectory ( this is a hidden file to windows, another reason to use Linux ksh)
Master Script
Code:
#!/bin/ksh
############################################################
# This script creates the script to relocate DNAbuild working copies from         #
# the Solaris svn01g.gdc.net server to the svnprod.nwie.net server.                  #
############################################################
#
#Run the script to collect all DNA working copy locations ( find the .svn directories )
ScriptLoc="/home/scripts"
OutputLoc="/home/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"

cd ${bldDirLoc}

find . -type d -exec sh -c '[ -d "$1"/.svn ] || exit 1' sh {} \; -print | cat > ${OutputLoc}/dnaRelwc1.txt
 
#sort file and remove ./ from the beginning of each line

`cat ${OutputLoc}/dnaRelwc1.txt` | sort -u | sed '$!N; /^\(.*\)\n\1$/!P; D' | sed 's/^.\{2\}//g' | cat > ${OutputLoc}/dnaRelwc1.dat

# Run script that create final script for the svn relocate command for each working copy found. <---What we have been working on --->

Code:
${ScriptLoc}/createRelocwc.sh > ${OutputLoc}/relocdnawc.sh

createRelocwc.sh (with comments added here)
Code:
#!/bin/ksh
#################################################################################
# This script uses grep and gets the working copy locations from the dnaRelowc1.dat file                            #
# and creates a script with the relocate command to relocate DNA build working copies from                      #
# the  svn01g.gdc.net server to the svnprod.nwie.net server.                                                                                #
#################################################################################
#
# Read the list of Subversion working copies directories to Relocate to new Subversion Server
OutputLoc="/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"
wcfiles=${OutputLoc}/dnaRelwc2.dat  
svnRelcmd="svn relocate"
set svnRelcmd

cd ${bldDirLoc}

for i in `cat ${wcfiles}`
do
    #get current host URL from each entries file
    OldRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1 | tr -d '\n'`
    #Replace each current host URL with New host URL
    NewRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1 | sed '/svn01g.gdc/ s/svn01g.gdc/svnprod/g' | sed 's/\/svn01p//g' | sed 's/\/Repositories//g'`
    #print line to change directory to each directory that contains the .svn(dotsvn) subdirectory (cd PATH)
    echo "cd" $i
    #print next line to execute command in each directory (svn relocate OldRepo NewRepo)
    echo -e "$svnRelcmd $OldRepo $NewRepo\c"
done

So here we are again

---------- Post updated at 07:27 AM ---------- Previous update was at 07:21 AM ----------

Note I am not interested in listing the path if the "entries" file contains a different host than whats in the script. The only purpose for the "entries" file is to see if it contains the correct host name nothing more the file is not used for anything else

---------- Post updated at 07:35 AM ---------- Previous update was at 07:27 AM ----------

The problem I see is listing the directory path in another file when the directory PATH contains a Directory Name that contain spaces. ok in Windows I guess but not in Linux.

Example:

windows cd /windows/program files puts you in the program files directory

linux cd /windows/program files seem to try and put you in a directory called program

so the file created by the script gives cd /windows/program not what it should be /windows/program files/

I even tried putting quotes around like "/windows/program files/data" in the first file
but when adding the cd via echo in the script it still drops the path at "/windows/program

so I wind up with

cd /windows/program
cd /files/data
which is not what I want

Last edited by methyl; 02-23-2012 at 09:48 AM.. Reason: remove 922 line double paste ; fix some code tags
# 35  
Old 02-23-2012
Quote:
#!/bin/ksh
############################################################
# This script creates the script to relocate DNAbuild working copies from #
# the Solaris svn01g.gdc.net server to the svnprod.nwie.net server. #
############################################################
#
#Run the script to collect all DNA working copy locations ( find the .svn directories )
ScriptLoc="/home/scripts"
OutputLoc="/home/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"

cd ${bldDirLoc}

find . -type d -exec sh -c '[ -d "$1"/.svn ] || exit 1' sh {} \; -print | cat > ${OutputLoc}/dnaRelwc1.txt

#sort file and remove ./ from the beginning of each line

`cat ${OutputLoc}/dnaRelwc1.txt` | sort -u | sed '$!N; /^\(.*\)\n\1$/!P; D' | sed 's/^.\{2\}//g' | cat > ${OutputLoc}/dnaRelwc1.dat
FIRST SCRIPT last line does not work at all (due to the backticks) and appears to write to the input file dnaRelwc1.dat when the next script actually reads dnaRelwc2.dat.
Perhaps you meant:
Code:
cat ${OutputLoc}/dnaRelwc1.txt | sort -u | cut -c3- >${OutputLoc}/dnaRelwc2.dat

Quote:
${ScriptLoc}/createRelocwc.sh > ${OutputLoc}/relocdnawc.sh
createRelocwc.sh
That explains where the output file comes from!

Last edited by methyl; 02-23-2012 at 10:43 AM.. Reason: corrupt paste
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate two variables and form the third variable

Hi Guys, I was scratching my head for this for half a day... finally not successful :confused: Following is the problem I have a variable $ var1=123 $ var2-234 $ var3=345 and another Variable $ i=1 Now i wanted to save these into a Variable as shown below for i in 1 2 3 do... (5 Replies)
Discussion started by: ramprabhum
5 Replies

2. UNIX for Dummies Questions & Answers

Formating variables in KSH

Hi Friends , I want to know how to format the output for the following: i searched in the forum and couldnt get the exact requirement. Thanks in advance . (2 Replies)
Discussion started by: i150371485
2 Replies

3. Shell Programming and Scripting

concatenate variables

I need to know how to concatenate variables in Debian. I am making a interactive script where it ask the user for info to add a user I pull the first letter from the first middle and last name into individual variables now i want to put them all in one variable so i can put it into useradd command ... (4 Replies)
Discussion started by: HackerSeabass
4 Replies

4. Shell Programming and Scripting

ksh - for loop with variables

Hi, I 'm trying to send an e-mail for every different line in the .txt for i in {1..$variable} do sed -n "/$i$/p" text.txt done I have two problems about this. First one is that for loop doesn't work and the second one is that i cant get the output of sed (4 Replies)
Discussion started by: ozum
4 Replies

5. Shell Programming and Scripting

concatenate variables problem

Hello, I have a tricky problem: I have a $file with a variable number of occurrences of "ORA-" (in this case two) .......... EXP-00008: ORACLE error 3113 encountered ORA-03113: end-of-file on communication channel EXP-00056: ORACLE error 1403 encountered ORA-01403: no data found... (9 Replies)
Discussion started by: Laurentiu
9 Replies

6. Shell Programming and Scripting

Combining two variables in ksh

I can't believe I can't figure this out... given this code: CARS_DATA_LIST=`cat /tmp/file1 | awk '{print $1}' ` FMSA_DATA_LIST=`cat /tmp/file2 | awk '{print $1}' ` The value of each of the above variables is: CARS = a b c d e f g FMSA = a b c q r s I want to declare a third... (8 Replies)
Discussion started by: Shoeless_Mike
8 Replies

7. Shell Programming and Scripting

How to preserve NL in Ksh variables?

I'm trying to set a variable to the output of a command. This is what the comand output to the display looks like: />hciconndump -v TOsiu Dump of connection(s): TOsiu ---------------------------------------------------------------------- Process: A60Tsiu Connection: TOsiu... (2 Replies)
Discussion started by: troym72
2 Replies

8. Shell Programming and Scripting

how to concatenate values of two variables with an underscore(_) in between

Hi, I'm new to shell programming. I have two variables a and b a=val1 b=val2 could anyone kindly post the shell script to concatenate the values of variable a and b with an underscore(_) in between? The final output should be val1_val2. (8 Replies)
Discussion started by: badrimohanty
8 Replies

9. Shell Programming and Scripting

subtracting variables in ksh

hi all, how do i subract variables in shell ?? am trying to space out the headers and the output generated by the shell so they all line up : currently the output is like this : servers : users server1 : 10 latestServer : 50 so i thought... (3 Replies)
Discussion started by: cesarNZ
3 Replies

10. Shell Programming and Scripting

variables in ksh

I'm new to unix scripting. How would I go about pulling the first 3 characters from a variable in ksh and storing in another variable? Thanks. (9 Replies)
Discussion started by: steve6368
9 Replies
Login or Register to Ask a Question