LinuxQuestions.org
Help answer threads with 0 replies.
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-08-2009, 09:10 AM   #1
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Rep: Reputation: 15
Need help with a date within a script


Hi,

I am trying to write this script to monitor a log file within the last 10 lines and take the current time and subtracted by 15 minutes. I am stuck at the date calculation part.

date
Thu Oct 8 09:08:50 CDT 2009

I would like to know the syntax on how to take this time current time and subtracted by 15 minutes.

Help!

Thank you in advance.

J
 
Old 10-08-2009, 09:39 AM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 7,289

Rep: Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384
What scripting language are you using? It would probably be easiest to use the unix timestamp to do the subtraction then convert back to the date format you want.
 
Old 10-08-2009, 09:41 AM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
I hope this isn't homework.

date can easily do this for you.

Try date -d "now -15 minutes"
 
Old 10-08-2009, 09:43 AM   #4
Doculus
LQ Newbie
 
Registered: Oct 2009
Distribution: Gentoo
Posts: 29

Rep: Reputation: 17
Try this:

Code:
date -d @$[$(date +%s) - (15*60)]
 
Old 10-08-2009, 09:45 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,098

Rep: Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381
Quote:
Originally Posted by xmdms View Post
Hi,

I am trying to write this script to monitor a log file within the last 10 lines and take the current time and subtracted by 15 minutes. I am stuck at the date calculation part.

date
Thu Oct 8 09:08:50 CDT 2009

I would like to know the syntax on how to take this time current time and subtracted by 15 minutes.
Well, what kind of script are you writing? Bash? Perl? Python?

The date command can do this for bash, read the man page. For example:
Code:
date --date="-1 days" +%Y%m%d
will bring you yesterdays date, in YYYYMMDD format.
 
Old 10-08-2009, 09:45 AM   #6
Doculus
LQ Newbie
 
Registered: Oct 2009
Distribution: Gentoo
Posts: 29

Rep: Reputation: 17
Until I tried mine, we got the real answer
 
  


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
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
help with Date command in script icw_sec Programming 6 01-06-2004 11:02 AM
Date in a BASH script... soulsniper Linux - Software 7 11-22-2003 06:08 PM
can't retrieve the date in my script wedgeworth Linux - Software 0 09-15-2003 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 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