Go Back   The UNIX and Linux Forums > Operating Systems > Linux > Red Hat


Red Hat Red Hat is the world's leading open source technology solutions provider with offerings including Red Hat Enterprise Linux (RHEL), Fedora, open source applications, security and systems management, virtualization, and Services Oriented Architecture (SOA) solutions.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-07-2013
Registered User
 
Join Date: Dec 2012
Posts: 65
Thanks: 3
Thanked 0 Times in 0 Posts
Right way to change time for a RHEL server

I had the query of what would be the right approach to change the time on the RHEL server. I have the following ways to do that:

1)

Code:
# date -s "2 OCT 2006 18:00:00"

Or

Code:
 
# date --set="2 OCT 2006 18:00:00"

2)

Code:
 
# date +%Y%m%d -s "20081128"

The second option though would only change the date but not the time.

I hope, my query is clear about what is the right way to change time for a RHEL server.

Please revert with the reply to my query.

Regards

Last edited by Scott; 01-07-2013 at 04:24 AM.. Reason: Code tags, please...
Sponsored Links
    #2  
Old 01-07-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,950
Thanks: 220
Thanked 760 Times in 664 Posts
The simplest way to set the date is as described in the manual page.


Code:
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

So that would be:

Code:
date 100218002006

Sponsored Links
    #3  
Old 01-07-2013
Registered User
 
Join Date: Dec 2012
Posts: 65
Thanks: 3
Thanked 0 Times in 0 Posts
thanks for your answer but can we include the seconds also.
    #4  
Old 01-07-2013
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,658
Thanks: 164
Thanked 646 Times in 623 Posts
If this is a production server:


Code:
1. you should be using ntp services, not manually changing dates
2. When you manually change date/time over any substantial time value 
   you run the risk of breaking things like cron jobs, or application software 
   with services that are time dependent.

answer to your question after you have the date completely correct, you can set time:


Code:
date '+%T'  -s "11:14:00"

note that it uses your example 2 of setting time.

and configure and start ntp.
Sponsored Links
    #5  
Old 01-08-2013
admin_xor's Avatar
Registered User
 
Join Date: Jun 2011
Posts: 450
Thanks: 13
Thanked 77 Times in 74 Posts
Well as pointed out, it's recommended to use the NTP servers for updating date/time using the ntpdate command.

If this is not available, then the next recommended method is to use the hwclock --hctosys command. This sets the system time as BIOS time.

date command should always be avoided as setting date and time with this command introduces errors in time which could mess things up like kerberos.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Time Sync issue on RHEL 5.3 uday123 Red Hat 2 10-12-2009 09:58 AM
Date time issues on RHEL sumitb74 UNIX for Dummies Questions & Answers 5 07-21-2008 06:46 AM
RHEL 4 U5 - Server immediate shutdown mr_bold UNIX for Advanced & Expert Users 2 08-04-2007 04:33 AM
RHEL 3 - how to change the SNMP community strings? BG_JrAdmin Red Hat 0 06-19-2006 04:22 PM
To simultaneously update password change in two server at a time s_chandrakar Shell Programming and Scripting 0 11-07-2005 09:25 AM



All times are GMT -4. The time now is 01:20 AM.