Wednesday, April 5, 2017

How to sort the contents of a file in linux

How to sort the contents of a file in linux

I have a file in a path /tmp which contains some rpm packages. I need to sort the file.

ll /tmp/pckg.txt
sort /tmp/pckg.txt > /tmp/s_pckg.txt
A new file /tmp/s_pckg.txt will be created and the contents in that file will be in sorted order.

sort -r /tmp/pckg.txt > /tmp/s_pckg.txt
Reverse sorted.

sort -nk2 /tmp/s_pckg.txt
On the basis of second column it will sort.

Useful command combination in System Administration

Useful command combination in System Administration

Once you are in a linux box, these commands will help you to save your time a lot.

[root@linuxblack tmp]# ps aux|grep nagios | awk '{print $2}'|xargs kill -9 to kill the process owned by nagios


[root@linuxblack tmp]# ll | grep 02:1| awk '{print $9}'| xargs gzip list and zip the files in a dir whose time is 02:1


[root@linuxblack tmp]# ll | grep Jul| awk '{print $9}'| xargs du -hs - list and display the disk usage


[root@linuxblack tmp]# lsof -i TCP:443|awk '{print $2}'|xargs kill -9 Kill the process listening on port 443

How to move a linux process to foreground and background

How to move a linux process to foreground and background

I started a java process (not using &), but i need to move that process to background and foreground.

1. First I stopped the process using CTRL+Z ,
2. I do a process grep and i could see its running, (ps aux|grep java)
3. I issues command "jobs", it return me a job ID.


Example : - In this case job id is : 1
-bash-4.1$ jobs
[1]+ Stopped java -jar


4. Command -bash-4.1$ fg 1 (will bring the job id 1 to foreground)
5. Command -bash-4.1$ bg 1 (will move the job id 1 to background)

How to move a website from one cpanel to another cpanel server

How to move a website from one cpanel to another cpanel server

Our requirement is to migrate a full website from old cpanel server to new cpanel server. This has to be done in command prompt.

Follow the steps:

1. Login to the old cpanel server as root.
2. Backup the whole website using the command: /scripts/pkgacct {cpanel_username}
3. It will create the backup in /home folder as /home/cpmove-cpanelusername.tar.gz
4. Copy the backup file to the new server: scp /home/cpmove-cpanelusername.tar.gz root@newserver.com:/home
5. Login the new server as root.
6. Verify the size of the backup files.
7. It's the time to restore the backup in new server: /scripts/restorepkg {cpanel_username}
8. This will help to re-create everything from old server to the new server.
9. Test and verify, then go ahead in changing the DNS.

Mattermost Error: MySQL FULLTEXT indexes issue in logs

Mattermost Error: MySQL FULLTEXT indexes issue in logs

While working on Mattermost in my local machine I got the following error:

MySQL FULLTEXT indexes

Solution for fixing the issue is:

1. Login the server
2. Login to the mysql prompt:
show table status;
3. There you can see all the tables are having Engine as MYISAM.
4. You need to update those tables as INNODB
ALTER TABLE <table name> ENGINE = INNODB;

This helped to solve the issue.

Scenario based VMware questions

Scenario based VMware questions

1. Which method you adopt for taking backup of ESXi configuration ?
2. vMotion failed at 27%. What could be the possible reasons ?
3. What could be the reason for failing a VM to start after moving from another VMware platform ?
4. Can we clone a VM without VCenter ?
5. What are the possible reasons for ESXi host shown as disconnected in vCenter ?
6. After VMware clone Redhat network interface is not detecting, what may be the reasons ?
7. How can we resize an IDE virtual disk in VMware ?
8. What could be the reason for Software iSCSI adapters are not visible ?
9. What could be the reason for "Cannot create VMs with virtual machine version 9 in ESXi" ?
10. How to extend a logical volume in Windows 2003 hosted in VMware ?
11. What are the different ways to shrink the size of a vmdk file ?
12. Application server hosted in VMs are facing performance degradation. How to confirm whether it is an application related issue or VMware related issue ?
13. How to remove iscsi targets from ESXi with 'Dead' or 'Error' status ?
14. Reclaim the size of a thin provisioned vmdk file ?
15. What are the possible reasons for the operation to resize a VM disk failed ?
16. What could be the reason for "VM appears as inaccessible in vCenter" ?

Tuesday, April 4, 2017

Search and Replace in Vi editor

Situation:

I have a file called main.html, I need to search and replace _output with OUTPUT.

Steps:

Open the file in vi editor - vi main.html
:%s/_output/g/OUTPUT
Save file

The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:

:%s/foo/bar/g
    Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.

:s/foo/bar/g
    Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.

:%s/foo/bar/gc
    Change each 'foo' to 'bar', but ask for confirmation first.

:%s/\<foo\>/bar/gc
    Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.

:%s/foo/bar/gci
    Change each 'foo' (case insensitive due to the i flag) to 'bar'; ask for confirmation.
    :%s/foo\c/bar/gc is the same because \c makes the search case insensitive.
    This may be wanted after using :set noignorecase to make searches case sensitive (the default).

:%s/foo/bar/gcI
    Change each 'foo' (case sensitive due to the I flag) to 'bar'; ask for confirmation.
    :%s/foo\C/bar/gc is the same because \C makes the search case sensitive.
    This may be wanted after using :set ignorecase to make searches case insensitive.