Shell script with date parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script with date parameter
# 1  
Old 12-09-2008
Shell script with date parameter

Hi All

I have a shell script which calls all the Teradata Utiltyes . There is a sudden change in the requirment .

What i'm asked to do is

pass on the DATE to the shell script which should take the date automatically and run the utilityes.

i.e. the date should not be passed on manulay.The date should be taken automatically.

Please suggest me something on this.

Thanks,
Vinay
# 2  
Old 12-09-2008
whats the date format that your script takes??
can you post the script??
# 3  
Old 12-09-2008
date parameter format

The date parameter is something like this

'20050101',20080101.
Irrespective of the date is correct or not we take the date with an intreval of 3 years.But that is the date format like

"yyyymmdd".
Please suggest me something

thanks,
Vinay
# 4  
Old 12-09-2008
Is this what you are looking for?

Code:
#  date '+%Y%m%d'
20081209
#  date --date='-3 years' '+%Y%m%d'
20051209
#  date --date='3 years' '+%Y%m%d'
20111209

# 5  
Old 12-09-2008
Date automatically

But will the shell script take the DATE automatically , If this condition is passed. I mean to ask is i dont want give the date maually.

When i run the script,it should take the date automatically.
# 6  
Old 12-09-2008
Code:
TODAY=`date '+%Y%m%d'`
YEARSAGO=`date --date='-3 years' '+%Y%m%d'`
echo "Today: $TODAY  3 Years Ago: $YEARSAGO"

Code:
# sh test.sh
Today: 20081209  3 Years Ago: 20051209

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. Shell Programming and Scripting

Script Shell Parameter

Hi I have two shell script, the second script takes as a parameter the output variable of the first script, please how to retrieve the variable from the first script to pass as a parameter to the second script? Script1.sh i=0 i=$(($i + 1)) Script2.sh echo $1 Thank you (0 Replies)
Discussion started by: chercheur111
0 Replies

4. Shell Programming and Scripting

Incrementing the date depending on the Counter (parameter) passed to the script

Hello Everyone, I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server. i.e. Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4). First I will check for the... (1 Reply)
Discussion started by: filter
1 Replies

5. Shell Programming and Scripting

get system date, format it, pass it as a parameter to a perl script - all in cron job

I am trying to get the string containing date - in a specfic format actually, although I think that part is inconsequencial - 1110226^1110226^1110226^1110226^1110226 - through echo or printf or in some other way - created within a cront job and passed as a parameter to a perl script. Now, I know... (3 Replies)
Discussion started by: v8625
3 Replies

6. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

7. Shell Programming and Scripting

replacing parameter in shell script

I have a script file as below named test1.sh sed -e 's/xxxkeys/$1/g' template1.asp > template1.txt sed -e 's/xxxkeys/$2/g' template2.asp > template2.txt sed -e 's/xxxkeys/$3/g' template3.asp > template3.txt sed -e 's/xxxkeys/$4/g' template4.asp > template4.txt I want to replace $1 with a,... (1 Reply)
Discussion started by: satgur
1 Replies

8. Shell Programming and Scripting

Passing Date as parameter with sh script

Hi I need to pass a date argument with my shell script. Can any one send me code for the same. eg For 15th Aug 2006. Iwant to pass parameter like this ./startenv.sh 08/15/2006. Everyday date argument must change. Will the below code work ? ./startenv.sh date '+%m/%d/%y' THanks... (1 Reply)
Discussion started by: pankajkrmishra
1 Replies

9. UNIX for Dummies Questions & Answers

Shell script with input parameter

Can anyone help me how to write a shell script which accepts input parameter. My requirement is as follows: I need to run a shell script with a input parameter, and inside the script i will create a file with this input parameter name. Please help me out to create such a shell script. ... (1 Reply)
Discussion started by: jhmr7
1 Replies

10. Shell Programming and Scripting

parameter file for a shell script

Hi I was able to pass parameters to a shell script from the command line but now, I am trying to make the shell script to get those parameters/values from a file. Please give me ideas how to do this or if you have an example or website that shows how to do this. I tried searches but it... (2 Replies)
Discussion started by: bryan
2 Replies
Login or Register to Ask a Question