Friday, December 9, 2011

Setting up data and time on Redhat

Now, Lets talk about the class requirement,
Pre-requisites:
1. Laptop with 4 GB or 6 GB of memory and at least 250 GB of disk space.
2. VMware or Virtual Box already installed on the system
   a. Download from
 - vmware.com
 - virtualbox.org
3. Go to Centos.org and download latest version of centos.
4. If you can't install it, at least complete registration part and download the software before come to class.
5. All readings and LAB exercise are due before start of the class.
6. Feel free to ask question at the beginning of the class or at the end of the class. Please respect other folks while asking questions.
7. Please turn off your phone while in class. If you are expecting a call, let the class know.




Date and Time Configuration

A. Using tools

1. Using Date/Time Properties Tool

To open the tool:-
Click on System --> Administration --> Date & Time from the top panel

or
type system-config-date command at a shell prompt
# system-config-date

2. Using Network Time Protocol

If you are using the tool, on the date and time properties windows,
check the box "Synchronize date and time over the network and add the ntp servers on the box.

To set up time zone, click on time zone tab and select your time zone info.


B. Using Commands

# date +%D -s YYYY-MM-DD
# date +%D -s 2011-11-25
eg: YYYY is a four-digit year, MM a two-digit month, and DD a two-digit day of the month


# date +%T -s HH:MM:SS
# date +%T -s 22:11:00 # Sets the time 10:11 PM.
Here, HH stands for an hour, MM-minute, and SS-second, all in a two-digit form.(24 hour time)

If your system clock is set to use UTC (Coordinated Universal Time)
# date +%T -s HH:MM:SS -u

to set the system clock to 10:11 PM using the UTC,

# date +%T -s 22:11:00 -u


Just to display the current date and time,
# date


C. Setting up Network Time Protocol

ntp helps you to synchronize the system clock with the remote host over the network.

1. Find out if ntp server you selected is available/accessible to use .
# ntpdate -q server_address
# ntpdate -q 0.north-america.pool.ntp.org

2. Sync your time with ntp server
# ntpdate server_address
# ntpdate 0.north-america.pool.ntp.org 1.north-america.pool.ntp.org

3. To enable it across the reboot.
# chkconfig ntpdate on

4. If sync is keep failing on boot, add an entry to /etc/sysconfig/network
NETWORKWAIT=1


hOW TO SET UP NTP USING /ETC/NTP.CONF FILE

1. Edit the file /etc/ntp.conf and the ntp server entry.

server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org
server 3.north-america.pool.ntp.org


For the initial sync, add iburst directive at the end of the each server line
eg:
server 0.north-america.pool.ntp.org iburst

2. Add the following entry on /etcntp.conf file,

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1

This gives unrestricted access to localhost only.

3. Now restart the ntp
# service ntpd restart

4. Enable ntpd daemon @boot time
# chkconfig ntpd on


============================================

Adding date and time on history command in linux

The out put of history command is :

632 find ./ -type f -mtime -15 -mtime +7 -name "logs.*" -exec tar -cvf /export/home/kbhusal/mytar.tar {} \;
633 ls -l /export/home/kbhusal/mytar.tar
634 tar -tvf /export/home/kbhusal/mytar.tar
635 find ./ -type f -mtime -15 -mtime +7 -name "logs.*" | xargs tar -cvf /export/home/kbhusal/mytar.tar
636 ls -l /export/home/kbhusal/mytar.tar
637 tar -tvf /export/home/kbhusal/mytar.tar
638 pwd
639 cd ..
640 ./scripts.ksh

If you want to know when that command was run, add the value for one environment variable, you are good to see out put with time stamp.

# export HISTTIMEFORMAT='%F %T ' or
# export HISTTIMEFORMAT='%F %T '
Where,
%F - sets year/month/day
%T - sets the time
Note: Add extra space after T to have a more white space between time and command field.

632 2011-12-02 15:42:09 find ./ -type f -mtime -15 -mtime +7 -name "logs.*" -exec tar -cvf /export/home/kbhusal/mytar.tar {} \;
633 2011-12-02 15:42:29 ls -l /export/home/kbhusal/mytar.tar
634 2011-12-02 15:43:56 tar -tvf /export/home/kbhusal/mytar.tar
635 2011-12-02 15:44:18 find ./ -type f -mtime -15 -mtime +7 -name "logs.*" | xargs tar -cvf /export/home/kbhusal/mytar.tar
636 2011-12-02 15:44:22 ls -l /export/home/kbhusal/mytar.tar
637 2011-12-02 15:44:32 tar -tvf /export/home/kbhusal/mytar.tar
638 2011-12-02 15:44:34 pwd
639 2011-12-02 15:44:35 cd ..
640 2011-12-02 15:44:37 ./scripts.ksh


to make it permanent across the reboot, add the entry to the profile file or the user specific profile file.

Append the variable to .bash_profile on users home directory.
# echo "export HISTTIMEFORMAT='%F %T '" >> ~kbhusal/.bash_profile

To make it effective to all users, add it to the profile file..

# echo "export HISTTIMEFORMAT='%F %T '" >> /etc/profile

No comments:

Post a Comment