Shell script for Creating Directory with name as system date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for Creating Directory with name as system date
# 1  
Old 12-06-2005
Shell script for Creating Directory with name as system date

Dear Sir/Madam,

I need a bit of your help. The problem is as follows :

I have to create a directory in unix whose name is that of system date in the dd_mon_yyyy format . I am able to extract a date in required format ina variable , but when i'm using this variable in mkdir it is not creating a directory of that date, rather it is creating the dirictory of the same name as the variable( mkdir accepts a string name for creating directories , but I don't know how to convert date to string using shell scripting). I am writing below the piece of script of what I am doing. Plz correct me where ever possible. i hope to see a nice running solution from your side.

>Today='date +%d_%m_%Y'
>set
>$Today
>mkdir $Today

I hope you will help me.

plz do mail me a solution at EMAIL ADDRESS REMOVED

Thanks in advance.
Arun

Last edited by Perderabo; 12-06-2005 at 09:14 PM.. Reason: Remove email address
# 2  
Old 12-06-2005
Please make sure that you have read our rules. And note:
(10) Don't post your email address and ask for an email reply. The forums are for the benefit of all, so all Q&A should take place in the forums.
# 3  
Old 12-06-2005
Try this code:
Code:
mkdir $(date +%d_%m_%Y)

or
Code:
mkdir `date +%d_%m_%Y`

# 4  
Old 12-07-2005
Re: Shell Scripting for creating dir with system date...

Hi,


I have tried using


Today='date +%m%d%Y'
set
mkdir $today


But its not working. I am working on telnet. Every time it is creating directory with name date +%m%d%Y .. Plz tell me what should i do.

Thanks
Aru
# 5  
Old 12-07-2005
Re: Shell Scripting for creating dir with system date...

Even with :

mkdir $(date +%d%m%Y)

it is giving the error syntax error : '(' unexpected


And with :

mkdir 'date +%m%d%Y'

it is creating dir with name date +%d%m%Y , but not with system date.

Plz help
# 6  
Old 12-07-2005
Whatever blowtorch has given works well for me.

What OS are you on ?

And it is not
Code:
mkdir 'date +%m%d%Y'

it is
Code:
mkdir `date +%m%d%Y`

Note the difference between ` and '

` is the backtick character above the tab key.
# 7  
Old 12-07-2005
try with blowtorch's code(mkdir `date +%d_%m_%Y`), its working fine.
You have to place the backquotes(`) before and after the date command, you might have placed single quotes check it once.

Regards,
Raju
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

3. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

4. UNIX for Dummies Questions & Answers

Creating a directory based on date

I want to create a directory based on date. I do not have date -d command. What I do have is: either use "date" command to get current date or DATE1=$(perl -e 'print scalar(localtime(time - 1 )), "\n";' |awk '{print $2,$3,$5}') |awk '{print $3}'can be modified to produce the desired year.... (3 Replies)
Discussion started by: newbie2010
3 Replies

5. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

6. Programming

Script for creating a directory & move the .tif files in it.

Hi Team, I have thousands of TIF files which are converted from PDF. Below is a sample of it. LH9406_BLANCARAMOS_2012041812103210320001.tif LH9406_BLANCARAMOS_2012041812103210320002.tif LH9406_BLANCARAMOS_2012041812103210320003.tif LH9411_ANGENIAHUTCHINSON_2012041812102510250001.tif... (9 Replies)
Discussion started by: paragnehete
9 Replies

7. Shell Programming and Scripting

Creating a directory if its non-existent within a script

Hi, is there a way to create a directory when its non-existent when trying to move files to this particular folder? Thanks much. (7 Replies)
Discussion started by: ida1215
7 Replies

8. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

9. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

10. Shell Programming and Scripting

shell script to selectively tar directory based on date

hye everybody :) , i'm new to the scripting world.. hope you guys can help me out with this one.. i'm trying to identify any directory under /tmp/saya that is created more than one day from the current date.. e.g, today is March 14, so any directory that has time stamp March 13 backwards, i... (2 Replies)
Discussion started by: fara_aris
2 Replies
Login or Register to Ask a Question