LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to set date time using a file content (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-date-time-using-a-file-content-781999/)

yaadgiri 01-13-2010 11:32 AM

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.

Tinkster 01-13-2010 11:40 AM

Hi, welcome to LQ!

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


Cheers,
Tink

yaadgiri 01-13-2010 07:45 PM

Quote:

Originally Posted by Tinkster (Post 3825338)
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.

Tinkster 01-13-2010 09:28 PM

Well ... it should work just like this then.

Code:

date -s "$(cat foo)"

Tinkster 01-13-2010 10:58 PM

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


All times are GMT -5. The time now is 05:53 AM.