Results 1 to 2 of 2
Hi All,
I have a requirement like this, I have to save log files appended with current date and time.I did "logger.sh > log`date +%T%D`" it is saying no such ...
- 09-05-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 2
Appending date to filenames
Hi All,
I have a requirement like this, I have to save log files appended with current date and time.I did "logger.sh > log`date +%T%D`" it is saying no such file or directory.I omitted %D then it works.But I need both.One more thing if I want to put a separator between time and date what to do.For example
log09:15:20$09/09/11
Thanks,
Arka
- 09-05-2011 #2
I can see the issue here. The date %D returns / formatted date. e.g. MM/DD/YY
This will obviously try saving to a file named YY in the folder called "%TMM/DD"
to get around this, you will likely need to use a different date format.
As for formatting it, you can literally put whatever formatting you want in the +string.
e.g. to get what you want, but with - instead of / in the date:
logger.sh > log-`date +%T$%m-%d-%y`"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327


Reply With Quote