1828001 Members
3930 Online
109973 Solutions
New Discussion

Korn Script.

 
Chris Tijerina_2
Occasional Advisor

Korn Script.

The script below for some reason is not working and it is not creating the directory that I need it to create.
And when it starts to loop I get a running out of swap space message. I finally kill the process and things are back to normal. So what am I doing wrong here?
The goal is to untar all files from a directory and have them output the tar files into a final directory, and if the dir does not exsist then create the dir directory.
--------Start of Scripts----------------------
tarpath=/home/s1perf
dumppath=$tarpath/interim
datapath=/opt/best1/local/collect/data
cd $dumppath
chown best1adm:support $dumppath/*
ls -1 *-*tar > $tarpath/babytar
cat $tarpath/babytar | sort | while read server_tarfile ; do
print;print;print
if [[ -f $server_tarfile ]] ; then
finalpath="$datapath/$(print $server_tarfile | cut -f 2 -d '.')_mn"
chown best1adm:support *
cd $finalpath
yes| tar xvf $dumppath/$server_tarfile
chown best1adm:support *
chmod 777 *
fi
done
if [[ -d $datapath ]] ; then
mkdir -p $datapath
chown best1adm:support $datapath
chmod 777 best1:support $datapath
fi
rm -r $dumppath/*
----------End of Script-----------------------
"If you choose not to decide, you still have made a choice."
4 REPLIES 4
Paula J Frazer-Campbell
Honored Contributor

Re: Korn Script.

Hi Chris

Try running it so;-

ksh -x <scriptname>

and watch where it loops.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Korn Script.

Hi again

Also when using unix commands in a script always be pedantic in the path.

ie not chown but /usr/bin/chown or /sbin/chown

Paula
If you can spell SysAdmin then you is one - anon
Deepak Extross
Honored Contributor

Re: Korn Script.

Chris,
Some general suggestions -

1. always delimint your variables in curly braces. when you say $dumppath/*, what you really mean is ${dumppath}/*.

2. specify the command interpreter to be used on the first line of your script like so:
#! /usr/bin/ksh
I've seen scripts without this behave very strangely because they were involed from csh.

3. just add a
set -x to your script and run - thst shoudl give you an indication of what is going wrong.

good luck.
Wodisch
Honored Contributor

Re: Korn Script.

Hello Chris,

for the trouble shooting part, you may just add the statements
set -x
set -v
to your script.
Then everything will be shown before and after substitution.

HTH,
Wodisch