LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2010, 09:52 AM   #1
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Rep: Reputation: 0
Question 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
 
Old 10-29-2010, 09:56 AM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
It's a simple change to that line:

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

Alunduil
 
Old 10-29-2010, 09:57 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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 (`).
 
Old 10-29-2010, 09:58 AM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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
 
Old 10-29-2010, 11:33 AM   #5
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
Thumbs up

thanks for the reply will try these later when home and let you know
joe
 
Old 10-29-2010, 04:49 PM   #6
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
Thumbs up

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
 
Old 10-29-2010, 05:21 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
If this is solved, mark the thread as solved.
 
Old 10-30-2010, 01:42 PM   #8
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
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
 
Old 10-30-2010, 01:52 PM   #9
martinbc
Member
 
Registered: Jun 2010
Distribution: Ubuntu, played with Puppy Slitaz & OpenSUSE
Posts: 40

Rep: Reputation: 4
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
 
Old 10-30-2010, 01:53 PM   #10
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
Thumbs up solved

hi all sorry sorted it be using
TobiSGD 'date'
thanks
joe
 
Old 10-30-2010, 08:37 PM   #11
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add 5 years to current date kuravalasekhar Linux - General 6 03-18-2010 11:36 AM
Add Date (day) to Filename greengrass Programming 1 01-15-2007 07:48 PM
How do I add the current date to a filename? sammysrefuge Linux - Newbie 2 03-18-2005 03:43 PM
Script add date to filename amphion Linux - Newbie 2 06-02-2004 08:12 AM
how to add date to filename x2000koh Programming 1 07-08-2003 10:44 PM


All times are GMT -5. The time now is 06:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration