Visit Our UNIX and Linux User Community


Script that creates directory structure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that creates directory structure
# 1  
Old 02-07-2012
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 Smilie

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:

Code:
 
_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:

Code:
 
#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:

Code:
 
+ 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

Last edited by colinwilson1303; 02-07-2012 at 11:51 AM..
# 2  
Old 02-07-2012
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:

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


Previous Thread | Next Thread
Test Your Knowledge in Computers #173
Difficulty: Easy
The key difference between Linux and many other popular modern operating systems is that the Linux kernel and other components are free and open-source software.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create Directory structure

Hello ; ) again Now I have my file like this : DIR2/DIR3 DIR2 DIR2/DIR3/DIR4/DIR5 I am looking for help to create a loop that will create the directory structure. I need something like this : If "DIR2" does not exist > Create IF "DIR2" exist already > check if onther "DIR"... (5 Replies)
Discussion started by: Aswex
5 Replies

2. Shell Programming and Scripting

printing a directory structure

Hey everyone I am just trying print a directory structure but I am not getting the desired output. I am using AIX. Script : input file contains : TNP\\ECOM\\test\\1 input_file=folders.txt cat $input_file | while read line do echo $line done (3 Replies)
Discussion started by: rocker_me2002
3 Replies

3. Shell Programming and Scripting

Shell script for a writing the directory structure to a file

Hi All, I am new user of shell scripting has come up with a problem. that I have a directory structure like : Home | |--------A | |----trunk | |-------A_0_1/ | | | |-------A_0_2/ | |--------B | ... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

4. UNIX for Dummies Questions & Answers

Directory Structure

Hi... I have a directory which has multiple directories and sub directories inside... what command should i use to get a list of all these directories, without the filenames.... (2 Replies)
Discussion started by: saharookiedba
2 Replies

5. Shell Programming and Scripting

Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted. I've be... (5 Replies)
Discussion started by: cat123
5 Replies

6. Shell Programming and Scripting

Need help in Directory Structure

I have writen the following code to show the dirctory structure. Can any body help me for using the recursive function in this code? echo "-(0)" echo "$HOME-(1)" cd ~ set * for i in `ls $HOME` do if then echo ".....${i}" cd... (5 Replies)
Discussion started by: murtaza
5 Replies

7. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

8. Shell Programming and Scripting

Need script to make big directory structure

Hi, I'm a novice and I'd like to make a directory structure with a hundred or so folders. I've tried mkdir /foo/foo1/etc... mkdir /foo/foo2/etc mkdir /foo/foo3/etc mkdir /foo/foo4/etc ...but it appends '@' to each folder name and then fails on the subdirectories. Is it better to use a... (2 Replies)
Discussion started by: kamur
2 Replies

9. UNIX for Dummies Questions & Answers

Copying a Directory Structure to a new structure

Hi all Is it possible to copy a structure of a directory only. e.g. I have a file with the following entries that is a result of a find :- /dir1/dir2/file.dbf /dir1/dir2/dir3/file1.dbf /dir1/file.dbf I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies

Featured Tech Videos