This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Wednesday, April 25, 2018

How to free the disk space from deleted files in which PIDs are still running?

Wednesday, April 25, 2018 0
Sometimes we have removed large size of logfiles or files from linux server as part of housekeeping. But it will not release the disk space while running lsof command

[root@testserver ~]# lsof / | grep -i deleted
sh          3716       root    4w   REG  249,0  2269000 3342481 /var/log/cellos/mcelogd-mon.log (deleted)
sh          3716       root    5w   REG  249,0  2333681 3342525 /var/log/cellos/mcelogd-mon.trc (deleted)
tgtd        4144       root    4w   REG  249,0 26684869 3342480 /var/log/cellos/qd.log (deleted)
tgtd        4144       root    5w   REG  249,0 27453138 3342483 /var/log/cellos/qd.trc (deleted)
tgtd        4145       root    4w   REG  249,0 26684869 3342480 /var/log/cellos/qd.log (deleted)
tgtd        4145       root    5w   REG  249,0 27453138 3342483 /var/log/cellos/qd.trc (deleted)
iscsiuio    4592       root    4w   REG  249,0 26684869 3342480 /var/log/cellos/qd.log (deleted)
iscsiuio    4592       root    5w   REG  249,0 27453138 3342483 /var/log/cellos/qd.trc (deleted)

Normally we need to stop the logging service (syslog) before deleting the log files or stop the service which is related to the files.
Stopping  log collection on running server is not good practice.

Then how to solve the issue?

Free the Disk Space

Find the PID of deleted process, go to /proc then nullify it.

[root@testserver ~]# cd /proc/3716/fd
[root@testserver fd]# ls -al
total 0
dr-x------ 2 root root  0 Apr  9 17:08 .
dr-xr-xr-x 9 root root  0 Apr  9 17:08 ..
lrwx------ 1 root root 64 Apr  9 17:08 0 -> /dev/null
l-wx------ 1 root root 64 Apr  9 17:08 1 -> /var/log/exadatatmp/__imglog_stdout__.tFvWrjjEZTPOJWm3racIEPF5W9YQqMI3
lrwx------ 1 root root 64 Apr  9 17:08 10 -> /dev/null
lrwx------ 1 root root 64 Apr  9 17:08 11 -> /dev/null
l-wx------ 1 root root 64 Apr  9 17:08 2 -> /var/log/exadatatmp/__imglog_stderr__.tFvWrjjEZTPOJWm3racIEPF5W9YQqMI3
lr-x------ 1 root root 64 Apr  9 17:08 255 -> pipe:[21686]
l-wx------ 1 root root 64 Apr  9 17:08 4 -> /var/log/cellos/mcelogd-mon.log (deleted)
l-wx------ 1 root root 64 Apr  9 17:08 5 -> /var/log/cellos/mcelogd-mon.trc (deleted)

The process ID 3716 running on 4w (write mode).

[root@testserver fd]# ls -al 4
l-wx------ 1 root root 64 Apr  9 17:08 4 -> /var/log/cellos/mcelogd-mon.log (deleted)

We can release the space by nullify this file.

[root@testserver ~]# >/proc/3716/fd/4
[root@testserver ~]# lsof / | grep -i deleted | grep -i 3716
sh          3716       root    5w   REG  249,0        0 3342525 /var/log/cellos/mcelogd-mon.trc (deleted)

Alternate way, we can compress the file or we can kill the PID if not needed.

Thursday, April 19, 2018

Facter command in Linux

Thursday, April 19, 2018 0
Facter command is used to Collect and display facts about the current server. The library behind Facter is easy to expand, making Facter an easy way to collect information about a system information such as hardware details, network settings, virtualization type and kernel/OS information from within the shell or within Ruby. If no facts are specifically asked for, then all facts will be displayed.

If we want to use facter command, we need to install facter rpm.

Display all facts

[root@testserver manifests]# facter
architecture => x86_64
augeasversion => 1.1.0
bios_release_date => 01/06/2018
bios_vendor => Xen
bios_version => 4.4.4OVM
blockdevice_xvda_size => 53687091200
blockdevices => xvda
domain => puppet.test.com
facterversion => 2.4.4
filesystems => ext4,iso9660
fqdn => testserver.puppet.test.com
gid => root
hardwareisa => x86_64
....
....
uptime_days => 62
uptime_hours => 1491
uptime_seconds => 5368909
uuid => 0004FB00-0006-0000-7071-48CB71E70F8A
virtual => xenhvm

Display a single fact

[root@testserver ~]#  facter interfaces
eth0,eth1,eth2,lo

Facts format as JSON

[root@testserver ~]# facter --json architecture kernel  uptime timezone puppetversion bios_vendor
{
  "timezone": "CAT",
  "uptime": "62 days",
  "architecture": "x86_64",
  "kernel": "Linux",
  "bios_vendor": "Xen",
  "puppetversion": "3.8.1"

Facts format as YAML

[root@testserver  ~]# facter --yaml architecture kernel  uptime timezone puppetversion bios_vendor
---
bios_vendor: Xen
kernel: Linux
uptime: 62 days
timezone: CAT
architecture: x86_64
puppetversion: 3.8.1

Facter will produce output by below format.
a. JSON
b. YAML
c. Plaintext

Thursday, April 12, 2018

How to change the default login shell by command line in linux server?

Thursday, April 12, 2018 0
By using chsh command we can change the default login shell to other shell.

By using -l option we can list the available login shell on linux server.

[root@testserver ~]# chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
/bin/ksh

Then which user login shell need to change, we can change by below command. (If a shell is not given on the command line, chsh prompts for one)

[root@testserver ~]# chsh hygmtng7
Changing shell for hygmtng7.
New shell [/bin/ksh]: /bin/bash
Shell changed.

Before
[root@testserver ~]# cat /etc/passwd | grep -i hygmtng7
hygmtng7:x:20009:20009::/gmtng7/hyperion:/bin/ksh

After
[root@testserver ~]# cat /etc/passwd | grep -i hygmtng7
hygmtng7:x:20009:20009::/gmtng7/hyperion:/bin/bash

Thursday, April 5, 2018

How to use --exclude option in du command

Thursday, April 05, 2018 0
du command is used to estimate file space usage.

Sometime we need to exclude some folder or files while running du command.
For that we can use below option to achieve that.

[root@testserver /]# du -sh * --exclude=repository --exclude=oem1

The above command will exclude the repository & oem folder  under / path.

Hope it helps.

Sunday, March 18, 2018

How to Add SSH Public Key to Remote Server(s) in a Single Command.

Sunday, March 18, 2018 0
Below command is used to copy the key to single server.

# cat id_rsa.pub | ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'

Below command is used to copy the key to multiple server. We can use for loop.

# for i in  `cat serverlist`; do echo $i; cat id_rsa.pub |
ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'; done

Hope it helps.

Wednesday, February 28, 2018

How to kill the IDLE pts/tty session in Linux Server?

Wednesday, February 28, 2018 0
 Kill the IDLE pts/tty session in Linux Server

Situation:
    Sometime script command may not be completed properly or sometime improperly closed ssh session makes the idle pts/tty session.
           
[root@dbserver ~]# w
 14:18:28 up 31 days,  4:18,  4 users,  load average: 3.35, 3.42, 3.41
USER     TTY      FROM  LOGIN@   IDLE     JCPU   PCPU  WHAT
root        pts/2    -            27Jan18   31days  0.00s  0.00s   script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log


Solution:
Here, sometime ps -ft command will not respond

[root@dbserver ~]# ps -ft pts/2
UID         PID   PPID  C STIME TTY          TIME CMD

So, search with process and kill the process id.

[root@dbserver ~]# ps -ef | grep -i /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     202948 185999  0 14:18 pts/4    00:00:00 grep -i /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     271243 113886  0 Jan27 pts/1    00:00:00 script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     271245 271243  0 Jan27 pts/1    00:00:00 script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
[root@dbserver ~]# kill -9 271243

Hope it helps.

Monday, February 26, 2018

How to create VLAN interface by using comand line in RHEL7

Monday, February 26, 2018 0
By using nmcli command we can craete the VLAN interface in RHEL7.

VLANs are isolated broadcast domains that run over a single physical network. They allow you to segment a local network and also to "stretch" a LAN over multiple physical locations. Most enterprises implement this on their network switching environment, but in some cases, the tagged VLANs reach your server.

For this case, our physical network interface is called enp0s3. The VLAN's ID is 501, and the IPv4 address is 192.168.1.10, with a subnet mask of 255.255.255.0 and a default gateway of 192.168.1.1.

Create vlan
[root@nsk ~]# nmcli connection add type vlan dev enp0s3 id 501 ip4 192.168.1.10/24 gw4 192.168.1.1
Connection 'vlan' (a01bd6a3-a486-4c5b-83af-73d7344cc388) successfully added.

Activate the connection
[root@nsk ~]# nmcli connection up vlan
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Check the Connection
[root@nsk ~]# nmcli connection show
NAME     UUID                                                                 TYPE                   DEVICE
enp0s3  191fbaab-7ac3-4616-9368-3b006cba3574      802-3-ethernet     enp0s3
vlan        a01bd6a3-a486-4c5b-83af-73d7344cc388      vlan                      enp0s3.501

[root@nsk ~]# nmcli device status
DEVICE          TYPE           STATE         CONNECTION
enp0s3          ethernet       connected    enp0s3
enp0s3.501   vlan              connected    vlan
lo                  loopback       unmanaged   --

[root@nsk ~]# nmcli device show enp0s3.501
GENERAL.DEVICE                   :    enp0s3.501
GENERAL.TYPE                      :      vlan
GENERAL.HWADDR                :     08:00:27:93:16:4B
GENERAL.MTU                        :    1500
GENERAL.STATE                    :    100 (connected)
GENERAL.CONNECTION        :   vlan
GENERAL.CON-PATH             :    /org/freedesktop/NetworkManager/ActiveConnection/3
IP4.ADDRESS[1]                     :      192.168.1.10/24
IP4.GATEWAY                         :      192.168.1.1
IP6.ADDRESS[1]                     :       fe80::ecb7:3969:728f:a67b/64
IP6.GATEWAY                         :       --
[root@nsk ~]#

The command line to create a VLAN with nmcli is very basic as it uses default values.

Below command will full option to create detailed VLAN interface.
[root@nsk ~]# nmcli con add help