how to add a date?
hi all
i have a line in a script that puts some text into a file echo "Couldn't find this at this time" >>/var/cccamlog/cccam.check this work ok but i would like to have the time printed auto co what do i have to do to the line to do it? "Couldn't find this at this time 10-10-2010 08:05pm thanks joe |
It's a simple change to that line:
Code:
echo "Couldn't find this at $(date)" >> /var/cccamlog/cccam.check Alunduil |
Try this:
Code:
echo "Couldn't find this at this time "`date` >>/var/cccamlog/cccam.check Code:
man date |
You need the `date` command. It has a manpage:
Code:
man date Code:
echo "Hello, I am a string with the date: $(date '+%a %b %c')" >> /some/file |
thanks for the reply will try these later when home and let you know
joe |
thanks GrapefruiTgirl
this is the one i like best works 100% thanks joe ps i have a lot to learn but will do it here for sure |
If this is solved, mark the thread as solved.
|
futher to the help i have noticed a slight hickup is seems to print the date twice so what have i done wrong?
echo "the date and time is $(date '+%a %b %c')" >>/var/cccamlog/card.check and in the log i get the date and time is Sat Oct Sat 30 Oct 2010 18:35:23 BST notice the sat oct and then sat 30 oct seem to be a bit repreated any ideas thanks joe |
Hi
The %a %b and %c are all options to select various parameters of the date %a shows the day of the week %b gives the month %c gives everything, day date month year and time all in one string To see all the options look at the output of Code:
date --help Martin |
solved
hi all sorry sorted it be using
TobiSGD 'date' thanks joe |
For the record: the %a %b %c I used were just for showing the example of syntax! OP was supposed to put his/her own format characters in there. :)
|
All times are GMT -5. The time now is 08:06 PM. |