May 15

Linux: Manage Time in Ubuntu Through Command Line

View Time

To view the current date and time, the following command will be enough

date
Set Time

To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command

sudo date newdatetimestring

where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below

nn is a two digit month, between 01 to 12
dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying
hh is two digit hour, using the 24-hour period so it is between 00 and 23
mm is two digit minute, between 00 and 59
yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
ss is two digit seconds. Notice the period ‘.’ before the ss.

Let’s say you want to set your computer’s new time to November 25, 2013, 21:40:55, then you would use:

sudo date 112521402013.55

It couldn’t be any easier, could it? The source of this information was a good post on Ubuntu Forums (Set time/date via command line).
Change Time Zone

You may update or change your time zone by

tzconfig
dpkg-reconfigure tzdata (thanks to Mario, see comment below)

This command will guide you through the process of setting a new time zone. You may also choose UTC (GMT) if you want.

If your system does not have tzconfig, you may use something else.

tzselect

If your system does not have tzdata, install it as below:

sudo aptitude install tzdata

This will provide a set of different time zones to choose. If you would like to set the time to UTC, choose the option which says something like ‘none of the above’, or ‘none of these’ or something to this effect. In my case it was option 11. Then it asks for difference from UTC (GMT and GST is also the same thing). I chose GST-0 as the option and it set the time as UTC.
Sync Clock Via NTP

If you want to sync your clock with NTP servers, it is also very easy. Just make sure you have the file ntp.conf file in /etc. How can you check it?

ls /etc/ntp.conf

If you see /etc/ntp.conf as a result, you already have that file. If the ls command gives an error, you do not have it. If so, you may create it yourself.

sudo vim /etc/ntp.conf

This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or one has to configure something first.  You need to install ntpd in order to make use of this ntp.conf file.

Whether you have the file already or not, make sure it has at least the following data

driftfile /var/lib/ntp/ntp.drift
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org

Here you may replace, add, and/or remove any servers you wish. You will find a list of time servers from the public NTP time server list.

You may manually sync the clock using the following

sudo ntpdate servername

where servername can be any public or private time server. You may always choose the following without hesitation

sudo ntpdate pool.ntp.org

If you don’t have ntpdate installed, you can install it via:

sudo aptitude install ntpdate

By: HS

Category: Linux | Comments Off on Linux: Manage Time in Ubuntu Through Command Line
April 21

Linux: Finding a File containing with a particular text (grep)

grep command form (syntax)

grep “text string to search” directory-path

Examples

For example search for a string called redeem reward in all text files located in /home/tom/*.txt directory, use
$ grep "redeem reward" /home/tom/*.txt

Task: Search all subdirectories recursively

You can search for a text string all files under each directory, recursively with -roption:
$ grep -r "redeem reward" /home/tom

Task: Only print filenames

By default, grep command prints the matching lines You can pass -H option to print the filename for each match.
$ grep -H -r “redeem reward” /home/tom
Output:

...
filename.txt: redeem reward
...

To just print the filename use cut command as follows:
$ grep -H vivek /etc/* -R | cut -d: -f1
Output:

...
filename.txt
...

By: Nixcraft
Category: Linux | Comments Off on Linux: Finding a File containing with a particular text (grep)
April 6

Linux: ZFS pool migration – troubleshooting notes – Ubuntu mount on reboot issues

Migrating and existing ZFS pool to a new server
1. Export spool from older server
2. Attach drives
3. Type: zpool import – The drives will be listed with their drive ID’s
First major issue:
In my case I had two ID’s for the two drives that were being mirrored.  I  could import either one, but importing the wrong one made it so I could no longer see the correct pool.  Even after a reboot the second and correct pool was unavailable to even be discovered.  I exported the pool and then reconnected the drives to my original server which was Open Indiana.  I then ran spool import and was able to see both ID’s I re imported the correct ID and everything was working on the original server.
Apparently I have created the same pool name under both ID’s the main issue was the first ID was version 13 and the second ID was version 28.  I exported the working pool imported the non working older pool and ran “zpool upgrade datapoolname 28”.  I exported the data pool again and reattached it to the new server.  This resolved some strange import errors.
4. spool import 11036020738792080304 -f
I was getting “directory not empty” errors and errors stating that the pools cannot be mounted.
5. Type: zfs get mountpoint – discovered that the SOURCE showed that the mount points were imported
I decided to clean up my mount points by reassigning them
I set the root directory mount point to none since the main volumes are underneath it and I was getting directory not empty errors
6. Type: zfs set mountpoint=none datapoolname
7. Type: ifs set mountpoint=/export/data/directoryname1 datapoolname/directoryname1
8. Type: ifs set mountpoint=/export/data/directoryname1 datapoolname/directoryname2
This change the SOURCE to a LOCAL setting
9. Typed:  zfs set sharesmb=on datapoolname – The pools would mount, but I would still get errors and they would not remount on a reboot.
This lead me to my final issue which became getting my zpool to mount on reboot.
After a couple of hours of reading and testing I discovered that a lot of people are having this problem with ZFS on Ubuntu.
10. I ended up modifying the end of /etc/rc.local with the following:
zfs mount -a
exit 0
Now on reboot the pools are automatically loading.

By: Nighthawk

Category: Linux | Comments Off on Linux: ZFS pool migration – troubleshooting notes – Ubuntu mount on reboot issues
April 5

Linux: Centos – System stops booting at atd service

In VirtualBox after upgrading Centos 6.3 to 6.4 the server would freeze after the graphical start-up bar moved all of the way to the right.
I dropped into single user mode on the server and ran init 5
The start up process would hang after posting “Starting atd [ok]”

I rebooted back to single user mode and went to see what service followed atd

I looked through /etc/rc5.d which lead me to rc.local being the last script to run
Nothing of significance was trying to run in rc.local

I made the assumption that the problem must be with gnome.

I ran startx

I received the message (EE)module ABI major version (10) doesn’t match the server’s version (13)

I went to /etc/X11/xorg.conf and mv’d it to xorg.conf-old

I then rebooted and the issue was resolved.

Category: Linux | Comments Off on Linux: Centos – System stops booting at atd service
April 2

Linux: ZFS pool migration

On the source system export the ZFS pool(s)
zpool export datapoolname

Remove the drives from the source system and attach them to the target system.After a few minutes type:
zpool import
pool: datapoolname
id: 15530172945248346540
state: ONLINE

Find  the data pool ID and type the following:
zpool import 15530172945248346540

Verify by typing the following:
zpool status

Category: Linux | Comments Off on Linux: ZFS pool migration