Script that creates directory structure

Hi All,

I have a script that does daily checks on my storage environment and is run from an AIX host.

The script currently works great but I have been changing and updating bits of it to make it easier for my lesser colleagues to understand :stuck_out_tongue:

However now with the updates I have made I have a problem. The thing is where the problem is was created by a UNIX scriptor who has now left and there is no one to help troubleshoot the command:

Problem is with creating a directory structure and my variables for creating this directory structure are:

 
_DATE_DIR="`date +%m"_"%b"_"%Y`"
_DATE_DAILY="`date +%d"."%b"."%Y`"
_DIRECTORY_PATH="/home/xxxxx/CAPACITY/REPORT/DAILY_CHECKS-VMAX/${_DATE_DIR}"
_LOG_FILE="$_DIRECTORY_PATH/${_DATE_DAILY}_Daily_Checks"

The directory structure is created using the following command and is the one command in the whole script I do not fully understand or are able to troubleshoot:

 
#MAKE DIRECTORY STRUCTURE IF IT DOES NOT EXIST
if [[ ! -d ${_DIRECTORY_PATH} ]]
then
 mkdir -p ${_DIRECTORY_PATH}
fi

when I run the script I get the following output:

 
+ date +%m_%b_%Y
_DATE_DIR=02_Feb_2012
+ date +%d.%b.%Y
_DATE_DAILY=07.Feb.2012
_DIRECTORY_PATH=/home/isoscwi/CAPACITY/REPORT/DAILY_CHECKS-VMAX/02_Feb_2012
_LOG_FILE=/home/xxxxx/CAPACITY/REPORT/DAILY_CHECKS-VMAX/02_Feb_2012/07.Feb.2012_Daily_Checks
+ [[ ! -d /home/xxxxx/CAPACITY/REPORT/DAILY_CHECKS-VMAX/02_Feb_2012 ]]
./new_daily_script: [[: not found
+ echo
./new_daily_script: /home/xxxxx/CAPACITY/REPORT/DAILY_CHECKS-VMAX/02_Feb_2012/07.Feb.2012_Daily_Checks: cannot create
 

I am sure this is something simple but I cannot see it myself. The "create the directory stucture" is what the UNIX guy created.

Any ideas on how I can fix this issue?

Cheers
Col

It is pretty simple. [[ -d "directoryname" ]] tests for the existence of a directory.

It seems that your shell doesn't like [[ brackets, though. You can replace it with something even simpler:

# If directory doesn't exist, run mkdir ${_DIRECTORY_PATH}
[ -d "${_DIRECTORY_PATH}" ] || mkdir "${_DIRECTORY_PATH}"