I have a directory with all tgz
files. Currently, I have a script that I run that will
- take in the directory as first parameter
- extract the
tgz
cd
into the extracted folder- and then run my load script
- and go on to the next tgz..
Shown below.
Currently this script works, but it will fail if someone puts in a parameter other than just the directory name (e.g, ./myScript /whole/path/to/directory)
dirname=$1
cur_dir=`pwd`
echo The directory you are about to extract is $dirname
echo $(ls ${cur_dir}/${dirname}/*.tgz)
echo Your current directory is ${cur_dir}
for tgz in $(ls ${cur_dir}/${dirname}/*.tgz) ; do # <---- I think there is a better way of doing this please advise
echo the tgz you are about to extract now is ${tgz}
cd ${dirname}; #cd into input directory
tar -xvzf ${tgz}; #extract tgz
cd ${tgz%%.tgz}; #cd into the folder you extracted
loadItExit; #run my other script to load
cd ../..; #move up two levels back to original path
done