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
5

Explanation:

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: , , , , ,

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: , , ,

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
123

Here, it will find the pid of nscd. the cut command will cut characters from 12 to 19 from output of 'ps -ef' command.
or
 #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/slapd.pid`  

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

Labels: , , , , ,

June 5, 2012

Disabling default GUI Startup Solaris 10

Many of us may not want to use the Solaris 10 Default JAVA or KDE default GUI. To startup Solaris 10 default in command Line mode you can make use of one of following:

1. You can use dtconfig command:
To disable GUI:
#/usr/dt/bin/dtconfig -d
To enable GUI:
#/usr/dt/bin/dtconfig -e
2. Disable/enable Service that handles cde-login:
To disable GUI:
#svcadm disable svc:/application/graphical-login/cde-login:default
To enable GUI:
#svcadm disable svc:/application/graphical-login/cde-login:default

It is that simple. No defense.

Labels: , , ,

April 18, 2012

Print first column of passwd

The delimiter used to differentiate different fields in the /etc/passwd files is colon ' : ' . Therefore we need to look only after the semicolon.
To deal with column based files or formatted text the most commonly used command is awk.
Command below will print out the first column of /etc/passwd file:

 awk < /etc/passwd -F: '{ print $1 }'

Here

awk             is the text processor

< /etc/passwd    will serve as input file for awk

-F:             is a parameter for awk that specifies the delimiter. In our      
                           case is colon.

{ print $1 }    This will print the first line. You can put $2, $3 etc. to
                           print respective column.

My command produced following output:

 root  
 daemon  
 bin  
 sys  
 adm  
 lp  
 uucp  
 nuucp  
 smmsp  
 listen  
 gdm  
 webservd  
 postgres  
 svctag  
 nobody  
 noaccess  
 nobody4  

Labels: , , , , , ,