Setting basename and dirname variable to simply script.

Hello all,

Can somebody explain to me how set up a basename and dirname variable to simplify this script. I currently have a 'infile' with the contents of FTTPDataPVC_ & BaaisDSLFeed. I need to add a basename and or dirname variable so that any additions can be made through the infile and not really have to modify the script itself. I'm kinda in a crunch, so your help is greatly appreciated. If you can offer any suggestions on how to make this work or a better solution in handling the script will really help.

#Here is my script

alertUser="johndoe@yahoo.com"
now=`date '+%m%d%y'`.txt
now2=`date '+%m%d%Y'`.txt
#BAAIS_MAIL=/apps/opt/tmp/baaisMFile

for i in `cat /apps/opt/tmp/baaisFile`
do

file=$(echo "${i}$now" | grep 'FTTPDataPVC_')

file2=$(echo ${i}$now2 | grep 'BaaisDSLFeed.')

if [[ -f /apps/opt/Batch/inbox/"${file}" ]] || [[ -f /apps/opt/BatchFeed/inbox/"${file2}" ]]
then
echo "${file} ${file2} file found"

    else


    echo "$\{file\} $\{file2\}  not found\\c  Please contact Production Support" >> /apps/opt/tmp/baaisMFile

fi

done

cat "/apps/opt/tmp/baaisMFile" | mailx -s "Alert: $(hostname) Baais File not Found" $alertUser

#rm -r /apps/opt/tmp/baaisMFile

Thanks,

AC

  1. Did you intend ${hostname} ?

  2. Personally I have all variables upper-case to make them obvious.

  3. Try..

DIRNAME=`dirname $SOMEFILE`
BASENAME=`basename $SOMEFILE`
echo $BASENAME is in $DIRNAME