Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ksh Script - copying files.

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
The following is the script that I am trying to run but for some reason it gives me an error when the dir = "int" part executes. I am running the script from the same server and I have two different environment. I have read access to the source directory and would like to copy those files to the destination directory where I am running the script from. Could someone please see if I am missing something here.

Many thanks

# Source and Destination folders.
srcbin=/d2/share/qa/bin
srcint=/d2/share/qa/int
destint=/d2/share/m1/int
destbin=/d2/share/m1/bin

filename=$1
#echo $filename

if [ $# -ne 1 ] ; then
echo "Invalid Arguments: Usage: getcm.ksh <FILENAME.EXT>"
exit 1
fi

# Strip the extension for the file.
filename=`echo "${filename%\.*}"`
#echo $filename

for dir in bin int
do
if [ "$dir" = "bin" ]
then
for ext in lst gnt
do
cp -p "$srcbin/$filename.$ext" $destbin
echo "Exit status = $?"
if [ $? -ne 0 ]
then
echo "Unable to copy $filename.$ext to $destbin"
exit 1
fi
done
fi

if [ "$dir" = "int" ] ; then
for ext in lst int idy cbl
do
cp -p "$srcbin/$filename.$ext" $destint
if [ $? -ne 0 ]
then
echo "Unable to copy $filename.$ext to $destint"
exit 1
fi
done
fi

done
 
... it gives me an error ...
It might help if you could give us that error too,
preferably cut & paste.
 
I cant see anything wrong with your code - and as the 'bin' section is working and the 'int' section is very similar I think the problem lies elsewhere. What error messages are you gettin? Have you tried running the script with the xv flags - i.e. ksh -xv myscript

Columb Healy
 
You may try this:
[ -f "$srcbin/$filename.$ext" ] || continue
cp -p "$srcbin/$filename.$ext" $destint

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
perhaps you need to copy files from ${srcint} instead of ${srcbin} when doing the "int" part...

HTH,

p5wizard
 
p5wizard

thanks a lot for pointing it out. It was indeed a error. I was meant to copy the int part instead of the bin.

thanks everyone for your help. The issue has been resolved.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top