Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Shell script for Creating Directory with name as system date

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-06-2005
aarora_98 aarora_98 is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 January 2012, 3:07 AM EST
Location: Somewhere in the center of the world, away from northpole but not too close to south.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
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 08:14 PM.. Reason: Remove email address
Sponsored Links
    #2  
Old Unix and Linux 12-06-2005
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 27 April 2015, 10:26 AM EDT
Location: Ashburn, Virginia
Posts: 9,931
Thanks: 64
Thanked 447 Times in 264 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 12-06-2005
blowtorch's Unix or Linux Image
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 16 April 2015, 11:34 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
Try this code:

Code:
mkdir $(date +%d_%m_%Y)

or

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

    #4  
Old Unix and Linux 12-07-2005
aarora_98 aarora_98 is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 January 2012, 3:07 AM EST
Location: Somewhere in the center of the world, away from northpole but not too close to south.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 12-07-2005
aarora_98 aarora_98 is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 January 2012, 3:07 AM EST
Location: Somewhere in the center of the world, away from northpole but not too close to south.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 12-07-2005
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 12 March 2015, 5:33 AM EDT
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts
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.
Sponsored Links
    #7  
Old Unix and Linux 12-07-2005
rajus19 rajus19 is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 12 February 2013, 1:25 AM EST
Location: Bangalore
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script for creating a directory & move the .tif files in it. paragnehete Programming 9 05-04-2012 07:55 PM
Creating a directory if its non-existent within a script ida1215 Shell Programming and Scripting 7 04-09-2012 06:03 AM
How to increment a user defined date value in the DATE format itself using shell script? sunil087 Shell Programming and Scripting 1 12-22-2009 05:29 AM
Creating date directory and moving files into that directory ravi030 Shell Programming and Scripting 3 12-05-2008 03:18 AM
shell script to selectively tar directory based on date fara_aris Shell Programming and Scripting 2 03-16-2008 07:35 PM



All times are GMT -4. The time now is 01:54 PM.