LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-13-2010, 11:32 AM   #1
yaadgiri
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
How to set date time using a file content


I have a file called foo with a date string in it - and nothing else in the file

2010.01.13-22:28:28

I want to send this file content to date -s command so I can modify using a cron job.

I tried several ways to pipe the file contents to date command but did not work. Any tips/suggestions will be appreciated.
 
Old 01-13-2010, 11:40 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

What locale are you in, what's your "normal" date format?


Cheers,
Tink
 
Old 01-13-2010, 07:45 PM   #3
yaadgiri
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
Hi, welcome to LQ!

What locale are you in, what's your "normal" date format?

Cheers,
Tink
Latin1, India (EST) I can do date -s with the file contents (copy paste) and everything is fine.. maybe a simpler way is to just add "date -s" in front of the string and execute it as part of cron job. Thanks.
 
Old 01-13-2010, 09:28 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Well ... it should work just like this then.

Code:
date -s "$(cat foo)"
 
Old 01-13-2010, 10:58 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
On a different note: why on earth would you want to set
time & date from a file via a cron-job? At the end of the
day crons behavious depends on the time & date, so it
seems very odd to me to have it change those?


Cheers,
Tink
 
  


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
delete a file based on content and date ElectroLinux Linux - Newbie 7 08-19-2009 07:01 AM
Cannot set time/date to other time zone than UTC (Kubuntu) jamangold Ubuntu 1 12-23-2005 05:42 PM
how to set date and time thick_guy_9 Slackware 8 07-07-2005 08:46 AM
date command do not keep time set shanenin Linux - Software 1 09-04-2004 08:16 PM
set date and time maggielmk Programming 3 10-24-2001 01:21 AM

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

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