![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
|
Using Date in Bash Scripting
Hi
I am trying to write a bash script crefil whose purpose is to create a file in mt home directory.........I wanted this feature to be into it. Whenever I run the program it should create a file with a different name........say depending on the date...........if it is 9th of april 2005 then the file name should be file090405.txt.........Is it possible to achieve? Thanks for the help. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
sure, just use exec('touch `date`.txt') and use a format for date to get the right format you desire. check the man page of date
|
|
|
|
|
|
#3 | |
|
Newbie
|
Quote:
Thanks for the reply.........But i am getting syntax error when using it........Please can you give more details how to use it? |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
echo $(date +%m%y%d)
I decided to do some research to learn a little on bash scripting...
__________________
|
|
|
|
|
|
#5 | |
|
Newbie
|
Quote:
Thanks for the reply...........But when I use this the script is creating a file by name echo How will I make it understand that is a command? |
|
|
|
|
|
|
#6 |
|
Professional Programmer
|
right, i just forgot the format off the top of my head
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
#!/bin/sh touch `date +%m%y%d`; |
|
|
|
|
|
#8 |
|
Newbie
|
Hi
If I try that command in ther terminal it works. But if I use the same thing in a bash script it does not #!/bin/bash /bin/tar -zcpf /home/raghu/cron/touch `date +%m%y%d`.tar.gz /home/raghu/.gaim/logs/yahoo/raghavendra83 It creates a file with name touch and not a file with the filename of date What should I do to solve this? |
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() ![]() |
throw the command in a variable and execute it from the script... here is a basic example...
#!/bin/sh MYFILE=`date +%m%y%d`; echo $MYFILE; DATA="this is a test"; echo "$DATA" >> $MYFILE; MYCMD="cat $MYFILE"; $MYCMD
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#10 |
|
Newbie
|
Hi
Thanks for your reply. Your suggestion worked like a charm. I did make some changes to suite my needs but it was built upon your idea ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|