LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to add a date? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-a-date-841163/)

joesto 10-29-2010 08:52 AM

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

alunduil 10-29-2010 08:56 AM

It's a simple change to that line:

Code:

echo "Couldn't find this at $(date)" >> /var/cccamlog/cccam.check
Regards,

Alunduil

TobiSGD 10-29-2010 08:57 AM

Try this:
Code:

echo "Couldn't find this at this time "`date` >>/var/cccamlog/cccam.check
For more options about the date command try
Code:

man date
, only make sur to put the options and the date command in backticks (`).

GrapefruiTgirl 10-29-2010 08:58 AM

You need the `date` command. It has a manpage:
Code:

man date
You want to insert it into your echo string, like:
Code:

echo "Hello, I am a string with the date: $(date '+%a %b %c')" >> /some/file

joesto 10-29-2010 10:33 AM

thanks for the reply will try these later when home and let you know
joe

joesto 10-29-2010 03:49 PM

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

MTK358 10-29-2010 04:21 PM

If this is solved, mark the thread as solved.

joesto 10-30-2010 12:42 PM

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

martinbc 10-30-2010 12:52 PM

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
Then select whichever parameter(s) you want.

Martin

joesto 10-30-2010 12:53 PM

solved
 
hi all sorry sorted it be using
TobiSGD 'date'
thanks
joe

GrapefruiTgirl 10-30-2010 07:37 PM

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.