• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 787
  • Last Modified:

"date" parameter in Batch Files (unix)

Hi.

In DOS, there is a paramether that you can use on your batch file that passes the date of the system (for example, "echo %date%").

Is there a similar parameter on Unix?

Thanks.
0
kalvillo
Asked:
kalvillo
  • 5
  • 3
1 Solution
 
ozoCommented:
echo `date`
or just
date
0
 
kalvilloAuthor Commented:
do you know how to print the ` character on vi?
0
 
kalvilloAuthor Commented:
hi...

Let me explain what i'm trying to do...

I want to make a batch file that builds a tar file with the date on the name, for example "file10-02-09"

`date`returns me the complete date (tue feb 10 14:37:00 pst 2009)

Is there a way to do this?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ozoCommented:
#!/bin/bash
name=file`date '+%d-%m-%y'`
 echo $name
0
 
ozoCommented:
you could also use
name=file$(date '+%d-%m-%y')
0
 
kalvilloAuthor Commented:
This is the code of my batch file:


#!/bin/bash
name=file$(date'+%d-%m-%y')
tar -cvf /respaldo-mail-huevo/gabriel/name.tar /var/qmail/mailnames/huevocartoon.com/gabriel
gzip /respaldo-mail-huevo/gabriel/name.tar

It creates the following file:

name.tar.gz

It should be

name10-02-09.tar.gz

What am i doing wrong?
0
 
ozoCommented:
space between date and the format
name=name$(date '+%d-%m-%y')
$ to expand the variable
tar -cvf /respaldo-mail-huevo/gabriel/$name.tar /var/qmail/mailnames/huevocartoon.com/gabriel
0
 
ozoCommented:
gzip /respaldo-mail-huevo/gabriel/$name.tar
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now