[HOW TO] Hardware date and Time Using hwclock

hwclock is a program that runs under Linux and sets and queries the Hardware Clock, which is often called the Real Time Clock, RTC, or CMOS clock. This is the program that most Linux systems use to get the time from the Hardware Clock and set the System Time at boot time. This program works on ISA (Intel), Alpha, Sparc, and M68K systems with or without /dev/rtc.


hwclock contains facilities for compensating for systematic drift in the Hardware Clock.


Set the hardware date and time based on the system date as shown below:

#hwclock -systohc
#hwclock --systohc -utc

Use hwclock without any parameter to view the current hardware date and time:

#hwclock

Check the clock file to verify whether the system is set for UTC:

#cat /etc/sysconfig/clock 


Reference 1: http://linux.101hacks.com/date-manipulation/hwclock/
Reference 2: http://linux.101hacks.com/date-manipulation/set-system-date-and-time/
Reference 3: http://manpages.ubuntu.com/manpages/lucid/man8/hwclock.8.html


TiếnPT - R0039

[HOW TO] Find out the IP address assigned to eth0 and display IP only?

Q. I need to get the IP address assigned to eth0 Linux interface. How do I find out IP address only? I don't want other information displayed by Linux ifconfig command.
A. For shell script or may be for other cause you may need the IP address only. You can use ifconfig command with grep and other filters.
Default output of /sbin/ifconfig command is all interfaces:
$ /sbin/ifconfigOutput:
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:69527 errors:0 dropped:0 overruns:0 frame:0
          TX packets:69527 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:41559546 (39.6 MiB)  TX bytes:41559546 (39.6 MiB)
eth0      Link encap:Ethernet  HWaddr 00:17:9A:0A:F6:44
          inet addr:192.168.2.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::217:9aff:fe0a:f644/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:227614 errors:0 dropped:0 overruns:0 frame:0
          TX packets:60421 errors:0 dropped:0 overruns:0 carrier:0
          collisions:272 txqueuelen:1000
          RX bytes:69661583 (66.4 MiB)  TX bytes:10361043 (9.8 MiB)
          Interrupt:17
ra0       Link encap:Ethernet  HWaddr 00:50:56:C0:00:01
          inet addr:192.168.1.2  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1024 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1320 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
Now you just select eth0 as follows:
$ /sbin/ifconfig eth0
Now you just wanted the IP address, use grep to get the IP:
$ /sbin/ifconfig eth0| grep 'inet addr:'Output:
inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
To get IP address from use cut command:
$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2Output:
192.168.2.1  Bcast
Finally remove Bcast with awk
$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
Output:
192.168.2.1
See how to read UNIX/Linux system IP address in a shell script
TiếnPT - R0039

[HOW TO] view log files *.bz2

In a few time, you need to read log file format bz2. This article explain how to view a log file compressed in gnuzip format. Below is the command to view compressed file in bzip2 format instead :
bzcat <.tar.bz2 or .bz2 compressed file>

bzcat logfile.tar.bz2
Again, if the log file is more then a screen full, use less to pause every screen full.

bzcat logfile.tar.bz2 | less
Alternatively, use the "bzless" command. It will also pause every screen full.
bzless <.tar.bz2 or .bz2 compressed file>

bzless logfile.tar.bz2

[HOW TO] Change SATA Hard Disk Mode from IDE to AHCI / RAID in BIOS after Installing Windows?

Today we are going to address a very common but one of the most irritating problems in this tutorial.
Consider following scenario:
You got a new computer system in which the SATA hard disk controller mode in BIOS settings was set to IDE ( or IDE Compatibility or Standard IDE) instead of AHCI (Advanced Host Controller Interface) or RAID for better compatibility. You didn't notice that and installed Windows. After sometime you realized it and changed the SATA mode from IDE to AHCI or RAID in BIOS and BOOM!!! You made your Windows crashed. Windows will no longer start and will show a BSOD (Blue Screen Of Death) containing error code "STOP 0x0000007B INACCESSABLE_BOOT_DEVICE".
Why??? Because Windows can't load the new drivers for AHCI or RAID interface. Actually when Windows is installed, it automatically disables unused storage drivers to speed up Windows startup process.
As a temporary fix, you can reset the SATA mode from AHCI or RAID to IDE in BIOS but you'll find yourself in the same situation. Or you can reinstall Windows but that would require lots of time and efforts.
Then how to switch SATA hard disk mode from IDE to AHCI or RAID in BIOS after installing Windows so that you would not need to repair or reinstall Windows?
Here is the solution! You just need to tell Windows that hard disk mode is going to change upon reboot using Windows Registry and Windows will automatically detect the mode and will install the required drivers and you'll be able to successfully change the SATA mode in BIOS without any need to reinstall Windows.
So without wasting time lets start the tutorial:
1. First DO NOT change SATA hard disk mode settings in BIOS, leave it to the default settings which were used while installing Windows.
2. Now start Windows and type regedit in RUN or Start Menu search box and press Enter. It'll openRegistry Editor.
3. Now go to following keys one by one:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\msahci
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\pciide
In right-side pane, look for a DWORD "Start". Double-click on it and set its value to 0 (That's zero and not alphabet O).


4. If you are using RAID or other interface, do the same thing for following key as well:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\iaStorV
In right-side pane, look for a DWORD "Start". Double-click on it and set its value to 0 (That's zero and not alphabet O).

5. That's it. It'll reset the hard disk mode settings in Windows registry. Close Registry Editor and restart your system.
6. Now enter into BIOS settings and change SATA hard disk mode to AHCI or RAID according to your requirements.
7. As soon as Windows will start booting, it'll automatically detect the change and will install the appropriate drivers. Once the drivers are installed, Windows will boot without any problem and you'll not need to reinstall Windows just to change SATA hard disk mode.
PS: If you don't want to edit the registry manually and want a ready-made registry script to do the task automatically, download following ZIP file, extract it and run the extracted REG file. It'll ask for confirmation, accept it:
TiếnPT - R0039