mnmonu
June 2, 2009, 10:02am
1
Hi
I have one properties file containing as
$INSTALL_BASEPATH/mssages/commonmessages_default.properties
$INSTALL_BASEPATH/resource/configurationBundle.properties
and $INSTALL_BASEPATH is set in .bash_profile
but from shell script when I read this file
and use in copy statement then it is not working
cp ${URL[j]} $distributionName/$dirstructure
where ${URL[j]}-------->file path read from properties file $distributionName/$dirstructure--------->destination directory
error---------->cp: cannot stat $INSTALL_BASEPATH/mssages/commonmessages_default.properties: No such file or directory
I know here possibly $INSTALL_BASEPATH value is not replace but how I can do lookup this value in shell script..........
Thanks in advance
mnmonu:
I have one properties file containing as
$INSTALL_BASEPATH/mssages/commonmessages_default.properties
$INSTALL_BASEPATH/resource/configurationBundle.properties
and $INSTALL_BASEPATH is set in .bash_profile
but from shell script when I read this file
and use in copy statement then it is not working
Have you exported the variable? If not, child processes will not see it.
In .bash_profile:
export INSTALL_BASEPATH
[quote]
mnmonu
June 2, 2009, 11:31am
3
[quote=cfajohnson;302321899]
Have you exported the variable? If not, child processes will not see it.
In .bash_profile:
export INSTALL_BASEPATH
Hi cfajohnson
Yes I have already entried in .bash_profile as
export INSTALL_BASEPATH=/vol2/RAORV_HOME
and I check it if I print the value from shell script it works well in cp command it's not working
This is my shell script
When I run it it gives the error in cp ${URL[j]} $distributionName/$dirstructure line
tempURL=`cat PropertiesFileURL_unix.txt|tr '\n' ' '|tr -d '\r'`
urlCount=(`echo "$tempURL" | sed 's/[^ ]//g' | wc -c` )
urlCount=`expr $urlCount - 1`
echo "urlCount------------->"$urlCount
URL=( $tempURL )
distributionName=`echo $INSTALL_BASEPATH|awk -F "/" '{print $NF}'`
ratingdirName=`echo $INSTALL_RATPATH|awk -F "/" '{print $NF}'`
for(( j =0; j< $urlCount ; j++ ))
do
echo -e "{URL[$j]}------------->"${URL[j]}
serverName=`echo ${URL[$j]}|awk -F "/" '{print $2}'|tr -d ' ' `
echo "serverName---------------->"$serverName
if [ $serverName == "abc-5.0" ]
then
dirstructure=`echo ${URL[$j]} | awk -F"/" 'BEGIN{ OFS="/" } {$1="";$NF=""; print $0 }'`
`mkdir -p $distributionName$dirstructure`
echo ${URL[j]}
cp ${URL[j]} $distributionName/$dirstructure
elif [ $serverName == "abcra-5.0" ]
then
dirstructure=`echo ${URL[$j]} | awk -F"/" 'BEGIN{ OFS="/" } {$1="";$NF=""; print $0 }'`
`mkdir -p $distributionName/$dirstructure`
elif [ $serverName == "abctl-5.0" ]
then
dirstructure=`echo ${URL[$j]} | awk -F"/" 'BEGIN{ OFS="/" } {$1="";$NF=""; print $0 }'`
`mkdir -p $distributionName/$dirstructure`
elif [ $serverName == "abcbill-5.0" ]
then
dirstructure=`echo ${URL[$j]} | awk -F"/" 'BEGIN{ OFS="/" } {$1="";$NF=""; print $0 }'`
`mkdir -p $ratingdirName/$dirstructure`
else
echo "Unknown"
fi
done
Please help me.......................
mnmonu,
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums
When you post code, please wrap it in
tags.
tempURL=`cat PropertiesFileURL_unix.txt|tr '\n' ' '|tr -d '\r'`
urlCount=(`echo "$tempURL" | sed 's/[^ ]//g' | wc -c` )
urlCount=`expr $urlCount - 1`
[/quote]
[indent]
You have six external commands in three lines. You need no more than 2. (You never need expr; the shell can do integer arithmetic.)
It's not clear exactly what you are counting, so it's hard to recommend any code.
Ah!
I think everything up to this point can be replaced with:
oIFS=$IFS
IFS='
'
URL=( $(tr -d '\r' < PropertiesFileURL_unix.txt) )
IFS=$oOFS
urlCount=${#URL[@]}
See? One external command!
You don't need awk:
distributionName=${INSTALL_BASEPATH##*/}
ratingdirName=${INSTALL_RATPATH##*/}
You don't need awk:
dirstructure=${URL[$j]#*/}
dirstructure=/${dirstructure%/*}/
Why do you have that in backticks?
And are you sure that $distributionName ends with a slash?
Does $distributionName/$dirstructure exist?
Hi
For testing purpose I have written another simple script till I am facing the problem Please help me
Now my parameter file test.txt contain
$INSTALL_BASEPATH/uninstall.sh
and my test script contain following (test.sh)
dir=`cat test.txt|tr -d '\n'`
echo "dir============"$dir
mkdir -p resources
cp $dir resources
I have checked well that uninstall.sh is exist in path $INSTALL_BASEPATH
and when I run the following
[raorv@qcldb2 test]$ ./test.sh
dir============$INSTALL_BASEPATH/uninstall.sh
cp: cannot stat `$INSTALL_BASEPATH/uninstall.sh': No such file or directory
but if I do cat $INSTALL_BASEPATH/uninstall.sh it shows the actual file content from shell script also
So where I am doing the wrong.$INSTALL_BASEPATH path already exported in .bash_profile
Plz help
This is not HTML; why are you using HTML tags?
The previous line is not code; why is it inside code tags?
Why are you using cat? It's an unnecessary external command.
dir=$( tr -d '\n' < test.txt )
But, since there's only one line in the file, you don't need any external command:
read dir < test.txt
Why are you calling the variable dir when the file contains a filename, not a directory?
You should check that mkdir was successful.
if ! mkdir resources
then
printf "could not create directory %s\n" "resources" >$2
exit 1
fi
You should check it in the script.
if ! [ -e "$dir" ]
then
printf "%s\n" "$dir does not exist" >&2
exit 1
fi
and when I run the following
[raorv@qcldb2 test]$ ./test.sh
dir============$INSTALL_BASEPATH/uninstall.sh
cp: cannot stat `$INSTALL_BASEPATH/uninstall.sh': No such file or directory
but if I do cat $INSTALL_BASEPATH/uninstall.sh it shows the actual file content from shell script also
So where I am doing the wrong.$INSTALL_BASEPATH path already exported in .bash_profile
In this script, your problem is that $dir will contain a literal '$INSTALL_BASEPATH/uninstall.sh'. The variable is not expanded.
Fix that with:
eval "dir=$dir"
You probably had the same problem in the original script, but you didn't tell us what was in the file, so we couldn't help you.
Hi GURU
Thanks , it was exactly what was required.For the next time I will use your valuable suggestion during coding...................