December 7, 2015

Counting number of users in a group - Linux

Here is a small command to find number of users in particular group on a *nix system. An example for wheel group:

grep wheel /etc/group | fgrep -o , | wc -m

Now here's a catch, this command actually counts the commas in the line from the group file. So if there are 5 users in the group, the output will be 4. You will have to add a 1 to the output.

So when using it in scripts, one can use it like this:

VAR1=$(($(grep wheel /etc/group | fgrep -o , | wc -m) + 1))
echo $VAR1


First grep will print only the group and its members. The members are seperated by a comma. Next we print the commas using -o option and later count them using wc command. The second example will just add a 1 to it.

Let me know if you have a better idea for the same!

Labels: , , , , ,

January 12, 2015

SystemManager.ks corrupted NetApp

NetApp OnCommand System Manager Fails to load with following error message:

OnCommand System Manager is unable to load the credentials because the file SystemManager.ks is corrupted. For more information, see the following section in the Release Notes: Unable to Launch System Manager.

Rename the following file and restart the OnCommand System Manager:





Labels: , , ,

September 5, 2014

Kickstart and Hostnames

The basic purpose to use kickstarts is to install numerous systems at a time with given para.
Configuring each system post install is tedious.
I found a workaround (that worked for me on Oracle Linux 6 and RHEL 6 and should most probably work for similar distros) to automate this task post install as well. If you know better solution, drop a comment below.

In the %post% section,

Add this:

 exec < /dev/tty6 > /dev/tty6 2> /dev/tty6  
 chvt 6  

This will switch to the 6th TTY and will drop into interactive shell. This allows installer to ask for information.

Let's try to ask for information:

 echo -n "Enter Hostname: "  
 read HOSTNAME1  
 echo -n "Enter IP Address: "  
 read IPADDR  
 echo -n "Enter Netmask: "  
 read NETMASK  
 echo -n "Enter Gateway: "  
 read GATEWAY  

Now that we have information, we can use the inbuilt cmd to configure the interface. I assumed first interface as eth0 (which it is in most cases. If you are not sure, you might want to add this to automation to detect what interface you have).

  echo -n "Applying network settings..."  
 echo "DeviceList.Ethernet.eth0.BootProto=static  
 ProfileList.default.DNS.Hostname=$" > /tmp/network-config  
 system-config-network-cmd -i -f /tmp/network-config &> /dev/null  
 service network restart &> /dev/null 

The system-config-network-cmd helps us import /tmp/network-config file.

Restarting network service later loads the new configuration.

To drop out of the TTY 6 and resume back to anaconda use chvt trick again:

 chvt 1  
 exec < /dev/tty1 > /dev/tty1 2> /dev/tty1  

Credits for chvt trick: Hintshop blog.

Labels: , , , ,

April 15, 2013

My Raspberry Pi Setup Part 1

The whole purpose to use raspberry pi in my house was to use it as a Bittorrent Downloader and File Server.

To know what Raspberry Pi is, go here:

Raspberry Pi runs linux operating system. To know more about it, go here:

I have it currently set up a simple set up as follows on my Model B RasPi.

Attached is:
1 16 GB Class 10 Transcend SD Card.
1 8 GB USB drive.
1 16 GB USB drive.
Network cable connected to my Router.
Power supply (Of course)

More powerful power supply will allow you to connect USB HDDs without additional power supply. For ex. if you connect a Samsung Phone Charger with 700 mA, you won't be able to connect external HDD without additional power supply.
I connected LG Charger that came with my Nexus 4, which produces 1.2 A output, seems to make my 1 TB WD external HDD work with the Pi.

Software Setup:
Raspbian OS (Previously I tried Arch, but I found raspbian nicer.)
LVM (Logical Volume Management)
Transmission BT

Initial Configuration:

Installed Rasbian OS on my Pi. To know how to do that go here:

By default, Raspberry Pi allows SSH access with the default username pi and password raspberry. I accessed it directly from the network.

Configure root password

 sudo passwd root  

command will allow you to change your root user password so that you can login using root account.
I always use root account and have never logged in using pi account.

Be careful. Logging in using root and performing incorrect operations may cause unstable OS or crash.

Configure Static IP address

To configure static IP address I simply edited my /etc/network/interfaces file that now looks like this:

 auto lo  
 iface lo inet loopback  
 iface eth0 inet static  

Then issued command

 service network restart  

Re-connected to my raspberry pi using new static IP address.

Update the pi

 apt-get update && apt-get -y upgrade  

Its always good to have this run first time, before you do anything.

The LVM setup

OK. The idea behind configuring LVM on my pi was nothing but to combine all the space available on different partitions to form a single logical volume and mount it at a single point, so that I can keep huge stuff inside single mount point.
Here's how my fdisk -l looks like:

Note: Removed information that is not required as of now.

  root@raspberrypi:~# fdisk -l   
  Disk /dev/mmcblk0: 16.1 GB, 16130244608 bytes   
  4 heads, 16 sectors/track, 492256 cylinders, total 31504384 sectors   
  Units = sectors of 1 * 512 = 512 bytes   
  Sector size (logical/physical): 512 bytes / 512 bytes   
  I/O size (minimum/optimal): 512 bytes / 512 bytes   
  Disk identifier: 0x00014d34   
    Device Boot  Start   End  Blocks Id System   
  /dev/mmcblk0p1   8192  122879  57344 c W95 FAT32 (LBA)   
  /dev/mmcblk0p2   122880  7454718  3665919+ 83 Linux   
  /dev/mmcblk0p3   7454719 31504383 12024832+ 8e Linux LVM   
  Disk /dev/sda: 8166 MB, 8166703104 bytes   
  224 heads, 63 sectors/track, 1130 cylinders, total 15950592 sectors   
  Units = sectors of 1 * 512 = 512 bytes   
  Sector size (logical/physical): 512 bytes / 512 bytes   
  I/O size (minimum/optimal): 512 bytes / 512 bytes   
  Disk identifier: 0x000ae796   
   Device Boot  Start   End  Blocks Id System   
  /dev/sda1   2048 15950591  7974272 8e Linux LVM   
  Disk /dev/sdb: 16.0 GB, 16008609792 bytes   
  64 heads, 32 sectors/track, 15267 cylinders, total 31266816 sectors   
  Units = sectors of 1 * 512 = 512 bytes   
  Sector size (logical/physical): 512 bytes / 512 bytes   
  I/O size (minimum/optimal): 512 bytes / 512 bytes   
  Disk identifier: 0x5ea0a18f   
   Device Boot  Start   End  Blocks Id System   
  /dev/sdb1   2048 31266815 15632384 8e Linux LVM   

OK. So there's three devices.
First memory card that RasPi boots from, Second the 8 GB USB and third 16 GB USB drives. /dev/mmcblk0, /dev/sda and /dev/sdb respectively.

There's two partitions on /dev/mmcblk0p1 and /dev/mmcblk0p2 used for RasPi itself. The third one was created by me. Note that the type of partition is Linux LVM. Similar partitions created on USB drive but only one on each that lie on full drive.

To know how to create a partition on a disk go here:

To know about LVM go here:

Now, we need a volume group.

# vgcreate /dev/mmcblk0p3 /dev/sda1 /dev/sda2  
 volume group datavg created.  
# lvcreate -l 100%FREE datavg  
 logical volume lvol0 created.  
# mkfs.ext4 /dev/datavg/lvol0

vgcreate will combine space from /dev/mmcblk0p3 /dev/sda1 /dev/sda2 to create a single Volume group.

lvcreate will create a logical drive out of that volume group.

mkfs.ext4 will create an ext4 filesystem on the logical volume.

We need to mount this new logical volume.

#  mkdir /data  
# mount /dev/datavg/lvol0 /data  
# chmod 777 /data  

So our new filesystem which comprises space from three devices, will be accessible on /data partition.

Now, we need this logical volume to be mounted across each reboot. To make it happen, ran following command.

# cp /etc/fstab /etc/fstab.bak  
# echo /dev/datavg/lvol0 /data ext4 defaults 0 2 >> /etc/fstab  

We're done!

I will write another article to describe how I installed software and its configuration.

Labels: ,

April 11, 2013

Making you SD card work with your Ubuntu / Linux Laptop or Desktop

You insert you SD card in your Ubuntu PC and it simply does not work. Most probably your kernel has not loaded module required for recognizing your SD card.

You must run all commands in this post as root.
[Optional] : To run commands as root run command "sudo su root" and to switch user as root.

First check if your PC detects the SD Card controller.
For that run command
lspci | grep -i sd

  root@ubuntu:~# lspci | grep -i sd   
  23:00.1 System peripheral: JMicron Technology Corp. SD/MMC Host Controller (rev 30)   
  23:00.2 SD Host controller: JMicron Technology Corp. Standard SD Host Controller (rev 30)   

As you can see above, my PC recognised JMicron SD Card controller.

To make your OS load module for SD Card controller, simply run these commands.

  root@ubuntu:~# echo tifm_sd >> /etc/modules   
 root@ubuntu:~# echo mmc_block >> /etc/modules   

And then reboot. Your OS should recognise your SD card.

Labels: , , ,

September 14, 2012

Publish SSH Server through TMG

Yet another casual but useful post.

Here's how I did it.

If you have a look at all the protocols available in Forefront Threat Management Gateway Toolbox, SSH is there, but it is outbound.

TMG forwards only inbound protocols. So, You will have to create a new protocol definition with nay name you like, port 22 and "inbound". And then create a non-web server protocol publishing rule.

It seems dumb but ate my 10 minutes.

That's it.

Labels: , , , ,

August 12, 2012

RTNETLINK answers: File exists

If you've come across error "RTNETLINK answers: File exists" when using dhclient to renew IP address, here's how I did it:

root@SERVER02 :dhclient eth0 -r  
root@SERVER02 :dhclient eth0  

The -r option releases current configuration for the interface, allowing dhclient to create new config file.

Labels: , , ,

August 8, 2012

6 things you probably want to do after Solaris 10 installation

1. Set BASH as default shell for root:
This is first thing I really do! Because bash has multiple advantages for day to day use and scripting too, over other shells.
For this you can simply edit /etc/passwd file and change the shell from very first line.
By default it is /sbin/sh, you can change it to /bin/bash

2. Change the hostname from "unknown"
To change the hostname temporarily:
 hostname SERVER01  
To change the hostname so that it is persistent across reboots:
 echo SERVER01 > /etc/nodename  
However, the changed hostname is re-set when you run sys-unconfig command to reset the configuration of the system.

3. Disable GUI Login:
 /usr/dt/bin/dtconfig -d  
For more, see here about disabling and enabling GUI login in Solaris

4. Configure loghost:
You might get messages such as "loghost could not be resolved.". To be able to resolve loghost you must configure DNS Server or you can add entry in /etc/hosts such as "  loghost".

5. Disable sendmail:
You can disable sendmail by issuing a simple command,
 svcadm disable sendmail  
Hmm... not everybody uses sendmail... 

6. Set PS1 variable (This is only for people using BASH):
It is solely user's choice to set this variable. Solaris has it as PS1='\s-\v\$ ' by default.
However, I set it as PS1="$LOGNAME@$HOSTNAME# " so that it will be displayed as:
 root@SERVER01# _  
For more information on PS1 environment variable check here and to make it look like Angelina Jolie :D check here.

Labels: , , ,

August 4, 2012

Solving basics hell out of vsftpd

Configuring vsftpd isn't a very hard thing. If you haven't read the docs, then its crucial to go.

I had a fresh installation of vsftpd on CentOS 6.2
I tweaked hardly one or two params in /etc/vsftpd/vsftpd.conf such as "anonymous_enable=NO"
Then created a new user using:

 #useradd -m -d /home/user1 -s /bin/bash user1  

Then I tried to connect to the server using our brand new user1.
Here's what I got:
500 OOPS: cannot change directory :/home/user1

After a bit digging on Google and thanks to this link, I was able to do it when I ran following command:

 /usr/sbin/setsebool -P ftp_home_dir 1  

This command takes a while to run, but it worked for me after that.
The setsebool sets boolean variables in SELinux.

Labels: , , , , , , ,

July 18, 2012

Find pid in Solaris 10

If you do not know the pid of a process, you can use "pidof" command in Linux. In case of Solaris, its not available.

Here's how you can find it:

 #ps -ef | grep nscd | grep -v grep | cut -c12-19

Here, it will find the pid of nscd. the cut command will cut characters from 12 to 19 from output of 'ps -ef' command.
 #ps -ef | grep nscd | grep -v grep | awk '{print $2}'
Here, we use awk to print second column of ps.

Labels: , , ,

Stopping OpenLDAP

This is most dumb but useful post. How to turn off slapd.

You know how to start the slapd:

 #/usr/local/libexec/slapd  [-option..]

however, pkill slapd is not the correct way to turn off slapd.

Here's how you turn it off:

 #kill -INT `cat /usr/local/var/`  

This will send appropriate signal to slapd process, and will store any cached data and close gracefully.

Labels: , , , , ,