How to create 2 different path folders?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create 2 different path folders?
# 8  
Old 02-02-2016
I can't see an attempt to tackle the deptno problem?

---------- Post updated at 17:49 ---------- Previous update was at 17:49 ----------

So I can't comment on it nor correct/improve it.
# 9  
Old 02-02-2016
Hi Boost,

Forgive me if I do not have time to go through your whole thread conversation, however, I would like to point out that one of the benefits of using the flag -p with mkdir is that it will not report errors, therefore you do not need the redirection > /dev/null 2>&1
Also you do not need to check if the directory exist since mkdir -p will do nothing if the directory exist.

Two create two directories:
Code:
mkdir -p /opt/test1/sample/abc /opt/test1/sample/def

Or:
Code:
mkdir -p /opt/test1/sample/{abc,def}

This User Gave Thanks to Aia For This Post:
# 10  
Old 02-02-2016
Ok.

My requirement is

if it is deptno=10 then
/opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH

if it is deptno=20 then
/opt/test/sample1/$CURRENT_YEAR/$CURRENT_MONTH/$DEPT_NO/$DEPT_NAME

/opt/test is already existing folder path.

finally create a folder as like below.

/opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH for deptno=10

/opt/test/sample1/$CURRENT_YEAR/$CURRENT_MONTH/10 and Sales for deptno=20

Please help me i am completely new this

---------- Post updated at 09:14 AM ---------- Previous update was at 09:01 AM ----------

Thanks Aja.
Code:
mkdir -p /opt/test1/sample/{$abc,$def}

like above right?

Could you please see my Post# 10

Thanks again!!

Last edited by Boost; 02-02-2016 at 01:19 PM..
# 11  
Old 02-02-2016
Hello Boost,

It is a request please use code tags as per forum rules for Inputs/codes/commands which you are using in your posts as per forum rules, following may help you in same.(Not tested though)
Code:
cat script.ksh
### NOTE: Please insert variables like CURRENT_YEAR etc values into script too.
mkdir /opt/test/sample/$CURRENT_YEAR
mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH
if [[ $deptno == 10 ]]
then
 mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/$DEPT_NO
else
 echo "Either value of deptno is NOT 10, please check.
fi
if [[ $deptno == 20 ]]
then
 mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/$DEPT_NAME
else
 echo "Either value of deptno is NOT 20, please check.
fi
mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/"10 and sales"

If not needed you could remove echo statements in above else statements. If you have some queries or getting issues please post complete requirement, with your O.S details too(along with code tags if necessary).

EDIT: Just now saw you have changed your POST#10 things a lot, following may help you in same, please try and let me know if this helps you then.
Code:
cat script.ksh
### NOTE: Please insert variables like CURRENT_YEAR etc values into script too.
mkdir /opt/test/sample/$CURRENT_YEAR
if [[ $deptno == 10 ]]
then
 mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/"10 and Sales for "$deptno
else
 echo "Either value of deptno is NOT 10, please check.
fi
 
if [[ $deptno == 20 ]]
then
 if [[ ! -d /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH ]]
 then
  mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH
 fi
 mkdir /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/"10 and Sales for "$deptno
else
 echo "Either value of deptno is NOT 20, please check.
fi

Thanks,
R. Singh

Last edited by RavinderSingh13; 02-02-2016 at 01:32 PM.. Reason: Added a note into script now. Added 1 more solution as user changed requirement shown in POST#10
This User Gave Thanks to RavinderSingh13 For This Post:
# 12  
Old 02-02-2016
Thank you ravinder.

What is wrong in my code
Code:
dept_no=`sqlplus -silent apps/test<<EOF  
                set pagesize 0
                set feedback off
                set verify off
                set heading off
                select deptno from emp
				where deptno=10;
                exit;
EOF`
echo $dept_no

dept_no1=`sqlplus -silent apps/test<<EOF 
                set pagesize 0
                set feedback off
                set verify off
                set heading off
                select deptno from emp
		where deptno=20;
                exit;
EOF`
echo $dept_no1
 
  DEPT_NO="DEPT"
  D_NAME="DNAME"

if [[ $dept_no == 10 ]]
 then
  mkdir -m 777 -p /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH >/dev/null 2>&1| tee -a  ${LOG_FILE_NAME}
 echo " Structure Created Successfully." | tee -a  ${LOG_FILE_NAME}
 else
 echo "10 dept Directory not created "| tee -a $LOG_FILE_NAME
 exit 2 
 fi

if [[ $dept_no1 == 20 ]]
 then
  mkdir -m 777 -p /opt/test/sample/$CURRENT_YEAR/$CURRENT_MONTH/$DEPT_NO >/dev/null 2>&1 | tee -a  ${LOG_FILE_NAME}
 echo " Structure Created Successfully." | tee -a  ${LOG_FILE_NAME}
 else
 echo "20 dept Directory not created "| tee -a $LOG_FILE_NAME
 exit 2 
 fi

could please help me

Last edited by Boost; 02-02-2016 at 04:36 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Urgent- shell script to create sub folders

Hi All, Could any one help me with a shell script which will create different sub folders in a folder and of which the sub folders names should be taken from a text file. Thanks (1 Reply)
Discussion started by: chetansingh23
1 Replies

2. UNIX for Dummies Questions & Answers

script to create folders

hi again, having an issue with the code here because it doesnt work :D can someone point what and how to change, please. #!/bin/bash #create directory mylabs, inside create 6 directories named by user. DIR1="$1" DIR2="$2" if ; then echo -n " there is a folder named mylabs, what... (1 Reply)
Discussion started by: me.
1 Replies

3. Shell Programming and Scripting

Create folders using masklist

hello there, I have a file called foldermasklist.txt have Aayush 1 source1/checksum Aayush 0 source2/checksum flexing 1 source1/source2/checksum flexing 1 time1/checksum in the format <parentfolder><flag><subfolders> script needs to read the flag if it's 1 then folder needs... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

4. Shell Programming and Scripting

Some manipulations with files and folders. (loop, find, create and remove)

Hello! I need to realize such task. 1. In my user's home dir I have folder1; 2. In folder1 I have some (various count) subfolders with random names; 3. In these subfolders I have one file anyname.pdf (various name in each subfolder) and file content.txt (constant name in each subfolder) ##... (7 Replies)
Discussion started by: optik77
7 Replies

5. Shell Programming and Scripting

Simple Script to create folders

Hi I want to write a small script that will create folders named from `AAAA' all the way to `ZZZZ'. That is: `AAAA' `AAAB' `AAAC' ... `AABA' `AABB' `AABC' ... `ABAA' `ABAB' `ABAC' ... `ABBA' ... `ZZZZ' (4 Replies)
Discussion started by: ksk
4 Replies

6. Shell Programming and Scripting

create folders until conditions met

Hi, I want to create 10 folders, starting from TEST001 till TEST010, after folder TEST010 is created the script should exit. Thanks in advance (1 Reply)
Discussion started by: bprabhukumar
1 Replies

7. Shell Programming and Scripting

Need to create a script to show what files in what folders

Hi everyone, I'm stuck with this scenario where our system creates files every night and puts them in several folders according from whom it came from. I have managed to create a script which will list the folders in one column and the files that are in them in another column, now my problem... (6 Replies)
Discussion started by: kumaran21
6 Replies

8. Shell Programming and Scripting

Help needed removing two top level folders from path

Hi, I am trying to use either awk or sed to drop the first two folders in a path. So if I had path /folder1/folder2/folder3/folder4.... I need to drop folder1&2, so the new path would be /folder3/folder4... If folder1 and folder2 were the same all the time, this would be easy. But... (4 Replies)
Discussion started by: robertinohio
4 Replies

9. Shell Programming and Scripting

how to create symbolic link between folders.....

hi champs, i have folders structure up to log is there , which is as below, app | |---version-4.1 | |----bin | | | | | |-----a.sh | | |-----b.sh | | | |----log | | \---version (symbolic link to version-4.1) but i want to create another folder... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

10. Shell Programming and Scripting

How to create folders/subfolders using shellscript

Hi, Can any one help me how to create folders using shellscript.My requirement is: FolderName: Main/Main1 :Main/Main2 :Main/Main3 underSubFolder : Main1/A :Main1/B :Main1/C underSubfolder: A/A1 ... (2 Replies)
Discussion started by: ram2s2001
2 Replies
Login or Register to Ask a Question