Tuesday, January 15, 2002

Fibonacci Series

Fibonacci series is series of natural number where next number is equivalent to sum of previous two number e.g. fn = fn-1 + fn-2. First two numbers of Fibonacci series is always 1, 1. In this Java program example for Fibonacci series we create function to calculate Fibonacci number and then print those numbers on Java console. Another twist in this questions is that some time interviewer ask to write Java program for Fibonacci numbers using recursion, so its better you prepare for both iterative and recursive version of Fibonacci number.

package com.test;

import java.util.Scanner;

/**
 * Java program to calculate and print Fibonacci number using both recursion and Iteration.
 * Fibonacci number is sum of previous two Fibonacci numbers fn= fn-1+ fn-2
 * first 10 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
 * @author
 */
public class Test2 {

    public static void main(String args[]) {
    
       //input to print Fibonacci series upto how many numbers
        System.out.println("Enter number upto which Fibonacci series to print: ");
        int number = new Scanner(System.in).nextInt();
      
        System.out.println("Fibonacci series upto " + number +" numbers : ");
        //printing Fibonacci series upto number
        for(int i=1; i<=number; i++){
            System.out.print(fibonacci2(i) +" ");
        }
    } 
  
    /*
     * Java program for Fibonacci number using recursion.
     * This program uses tail recursion to calculate Fibonacci number for a given number
     * @return Fibonacci number
     */
    public static int fibonacci(int number){
        if(number == 1 || number == 2){
            return 1;
        }
        return fibonacci(number-1) + fibonacci(number -2); //tail recursion
    }
  
    /*
     * Java program to calculate Fibonacci number using loop or Iteration.
     * @return Fibonacci number
     */
    public static int fibonacci2(int number){
        if(number == 1 || number == 2){
            return 1;
        }
        int fibo1=1, fibo2=1, fibonacci=1;
        for(int i= 3; i<= number; i++){
            fibonacci = fibo1 + fibo2; //Fibonacci number is sum of previous two Fibonacci number
            fibo1 = fibo2;
            fibo2 = fibonacci;
        }
        return fibonacci; //Fibonacci number
    }  
}

After asking to write simple Java program to print Fibonacci series and later asking for Fibonacci series using recursion, another important question interviewer ask is how do you improve your Fibonacci function both iterative and recursive one? A technique called memorization can be used to drastically improve performance of method which calculates Fibonacci number. if you look at the method it repetitive creates same Fibonacci number e.g. In order to calculate 10th Fibonacci number function first create first 9 Fibonacci number, this could be very time consuming if you just increase the upper limit from 10 to 10K. In memorization programming technique result of earlier calculation is cached and reused. So you don't need to create same Fibonacci number if you already have calculated it. You can write code for Fibonacci series with memorization by just using a HashMap  and checking if Fibonacci number for a corresponding number is already exits or not and calculate only if it doesn't exist.

    /*
     * Java Program to calculate Fibonacci numbers with memorization
     * This is quite fast as compared to previous Fibonacci function especially for
     * calculating factorial of large numbers.
     */
    public static int improvedFibo(int number){
        Integer fibonacci = cache.get(number);
        if(fibonacci != null){
            return fibonacci; //fibonacci number from cache
        }
        fibonacci = fibonacci2(number); //fibonacci number not in cache, calculating it
        cache.put(number, fibonacci); //putting fibonacci number in cache for future request
        return fibonacci;
    }

Comparison
        //comparison of performance of Fibonacci number with memorization
        int number = 100000000;
        long startTime = System.nanoTime();
        int result = fibonacci2(number); //fibonacci number with memorization
        long elapsedTime = System.nanoTime() - startTime;
        System.out.println("Time taken to calculate Fibonacci number upto 100M without memorization:" + elapsedTime);
      
        startTime = System.nanoTime();
        result = improvedFibo(number); //Fibonacci number with memorization
        elapsedTime = System.nanoTime() - startTime;

        System.out.println("Time taken to calculate Fibonacci number upto 100M with memorization:" + elapsedTime);

Interesting point is that improved method only shows better performance for large numbers like 100M otherwise iterative version of Fibonacci method is faster. That could be explained by extra work done by improved method in terms of storing value in cache and getting it from there.

Wednesday, June 27, 2001

How do I add cron job under Linux or UNIX like operating system?

Cron job are used to schedule commands to be executed periodically. You can setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.

crontab command
Root privileges Yes
Requirements crond
crontab is the command used to install, deinstall or list the tables (cron configuration file) used to drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.
Types of cron configuration files

There are different types of configuration files:

  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.
  2. The user crontabs: User can install their own cron jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab

How Do I install or create or edit my own cron jobs?
To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e
Syntax of crontab (field description)
The syntax is:
1 2 3 4 5 /path/to/command arg1 arg2
OR
1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command - Script or command name to schedule
Easy to remember format:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2
OR
1 2 3 4 5 USERNAME /path/to/script.sh
1: Minute (0 - 59)
2: Hour (0 - 23)
3: Day of month (1 - 31)
4: Month (1 - 12)
5: Day of week (0 - 7) (Sunday=0 or 7)

How do I use operators?
An operator allows you to specifying multiple values in a field. There are three operators:

  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
  2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".
  3. The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,....,13,14,15" using the comma operator.
  4. The separator (/) : This operator specifies a step value, for example: "0-23/" can be used in the hours field to specify command execution every other hour. Steps are also permitted after an asterisk, so if you want to say every two hours, just use */2.
More examples
#To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command

#Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh

#Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php

#Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl

# Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand

# Execute a cron job every 5 Minutes
*/5 * * * * /home/ramesh/backup.sh

# Execute a cron job every 5 Hours
0 */5 * * * /home/ramesh/backup.sh

# Execute a job every 5 Seconds
$ cat every-5-seconds.sh
#!/bin/bash
while true
do
 /home/ramesh/backup.sh
 sleep 5
done
Now, execute this shell script in the background using nohup as shown below. This will keep executing the script even after you logout from your session. This will execute your backup.sh shell script every 5 seconds.
$ nohup ./every-5-seconds.sh &

# Execute a job every 5th weekday
# The following example runs the backup.sh every Friday at midnight.
0 0 * * 5 /home/ramesh/backup.sh
(or)
0 0 * * Fri /home/ramesh/backup.sh
You can either user number or the corresponding three letter acronym for the weekday as shown below. [0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat]

# Execute a job every 5 months
0 0 1 5,10 * /home/ramesh/backup.sh
(or)
0 0 1 May,Oct * /home/ramesh/backup.sh


How do I disable email output?
By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1
To mail output to particular email account let us say vivek@nixcraft.in you need to define MAILTO variable as follows:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1

See "Disable The Mail Alert By Crontab Command" for more information.

Task: List all your cron jobs
Type the following command:
# crontab -l
# crontab -u username -l

To remove or erase all crontab jobs use the following command:
# Delete the current cron jobs #
crontab -r

## Delete job for specific user. Must be run as root user ##
crontab -r -u username

Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability. Special string Meaning
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".

Examples
#Run ntpdate command every hour:
@hourly /path/to/ntpdate
#Make a backup everyday:
@daily /path/to/backup/script.sh

More about /etc/crontab file and /etc/cron.d/* directories
/etc/crontab is system crontabs file. Usually only used by root user or daemons to configure system wide jobs. All individual user must must use crontab command to install and edit their jobs as described above. /var/spool/cron/ or /var/cron/tabs/ is directory for personal user crontab files. It must be backup with users home directory.

Understanding Default /etc/crontab
Typical /etc/crontab file entries:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
First, the environment must be defined. If the shell line is omitted, cron will use the default, which is sh. If the PATH variable is omitted, no default will be used and file locations will need to be absolute. If HOME is omitted, cron will use the invoking users home directory.

Additionally, cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob here. As a root user or superuser you can use following directories to configure cron jobs. You can directly drop your scripts here. The run-parts command run scripts or programs in a directory via /etc/crontab file:

Directory Description
/etc/cron.d/ Put all scripts here and call them from /etc/crontab file.
/etc/cron.daily/ Run all scripts once a day
/etc/cron.hourly/ Run all scripts once an hour
/etc/cron.monthly/ Run all scripts once a month
/etc/cron.weekly/ Run all scripts once a week
How do I use above directories to put my own scripts or jobs?

Here is a sample shell script called clean.cache. This script is created to clean up cached files every 10 days. This script is directly created at /etc/cron.daliy/ directory. In other words create a text file called /etc/cron.daily/clean.cache as follows.
#!/bin/bash
# A sample shell script to clean cached file from lighttpd web server
CROOT="/tmp/cachelighttpd/"

# Clean files every $DAYS
DAYS=10

# Web server username and group name
LUSER="lighttpd"
LGROUP="lighttpd"

# Okay, let us start cleaning as per $DAYS
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm

# Failsafe
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
        /bin/mkdir -p $CROOT
        /bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi
Save and close the file. Set the permissions:
# chmod +x /etc/cron.daily/clean.cache

How do I backup installed cron jobs entries?
Simply type the following command to backup your cronjobs to a nas server mounted at /nas01/backup/cron/users.root.bakup directory:
# crontab -l > /nas01/backup/cron/users.root.bakup
# crontab -u userName -l > /nas01/backup/cron/users.userName.bakup

 = = = = = = = = = = = = = = = = = = = =
Q) 
crontab -e
$ */5 * * * * root /root/restart.sh  >/dev/null 2>&1

#!/bin/bash
# Process Monitor
# Send e-mail alerts when service goes down
# -------------------------------------------------------------------------
# Author: Anup Dixit
# -------------------------------------------------------------------------
SUBJECT="Backup Exec Agent Failure"
EMAIL="myemail@email.to"
EMAILMESSAGE="/tmp/emailalert.txt"
#path to pgrep command
PGREP="/usr/bin/pgrep"

# Daemon name,
DAEMON="httpd"

# find daemon pid
$PGREP ${DAEMON}

if [ $? -ne 0 ] # if daemon not running
then
# Generate email message body
echo "This is servername at location. The Backup Exec service is no longer running." &gt; $EMAILMESSAGE
# send email alert
/usr/bin/mail -s "$SUBJECT" "$EMAIL" &lt; $EMAILMESSAGE
fi
= = = = = = = = = = = = = = = = = = = = = =

Wednesday, January 26, 2000

Control M Character [/bin/sh^M]

How to deal with ./configure : /bin/sh^M : bad interpreter ?

Windows and DOS terminate lines of text with CR (^M, or ASCII code 13) followed by LF (^J, or linefeed, ASCII code 10). Linux uses just LF, so the carriage returns appear as part of the text and are interpreted as such. That means they'll break scripts. 
Control-M(^M), an alternative way to do a carriage return in the ASCII character set.

We should understand a few things first:
CR = \r = Carriage Return
LF = \n = Line Feed

In DOS, all lines end with a CR/LF combination or \r\n.
In UNIX, all lines end with a single LF or \n.

The ^M that you are seeing is actually a CR or \r. If you want to test for carraige returns in a file, you want to look for \r. Try this on the file:
Code: od -c filename.txt

You'll see tabs, vertical tabs, carriage returns, linefeeds and whatnot using the slash notation. I find this to be the best method for determining what actual characters are in a file.
Or, if you just want to see the ^M notation, you can use cat, like so:
Code: cat -v filename.txt

To find whether a file has a CR or not you can use grep, this should print the lines with a CR:
Code: $ grep '^M' file1 # Type <Ctr-v><Ctr-m> to get ^M and not a ^ and an M.

  1. If you want to remove the ^M characters, you can use dos2unix as suggested above, or the correct tr syntax: Code: $ tr -d '\r' < infile.txt > outfile.txt
  2. Open file in VI Editor
    1. then press ESC then 
    2. :set fileformat=unix then
    3. :x! or :wq! to save file
  3. os2unix configure to fix this, or open it in vi and use :%s/^M//g; to substitute them all (use CTRL+V, CTRL+M to get the ^M)
  4. Or if you want to do this with a script: sed -i 's/\r//' filename
    1. $ cat file_name.sh | tr -d '\r' > file_name.sh.new
  5. If you're on OS X, you can change line endings in XCode by opening the file and selecting the [View -> Text -> Line Endings -> Unix] menu item, then Save. This is for XCode 3.x. Probably something similar in XCode 4.
  6. Download and install yourself a copy of Notepad++.
    1. Open your script file in Notepad++.
    2. File menu -> Save As ->
    3. Save as type: Unix script file (*.sh;*.bsh)
    4. Copy the new .sh file to your Linux system
    5. Maxe it executable with:  chmod 755 the_script_filename
    6. Run it with:  ./the_script_filename

Thursday, December 2, 1999

L I N U X - Simple But Important Command

Check OS & OS Version:

You can use any one of the following method to find out your Linux distribution and name:
a] /etc/*-release file.
b] lsb_release command [$ lsb_release -a].
c] /proc/version file.

How Do I Find Out My Kernel Version?
$ uname -a
$ uname -mrs
Sample outputs:
Linux - Kernel name
2.6.32-5-amd64 - Kernel version number
x86_64 - Machine hardware name (64 bit)

bash$ uname -srv
Linux 3.3.0-gentoo #2 SMP PREEMPT Wed Mar 21 02:07:10 CDT 2012
The first part prints out the kernel name, which is Linux in the above example. The second part is the kernel release version, which is 3.3.0-gentoo. The rest of it is a more detailed kernel information like the compilation date and config.
bash$ uname -mnipo
Output: machinename i686 Intel(R) Core(TM)2 Duo CPU E6850 @ 3.00GHz GenuineIntel GNU/Linux
machinename is the name of the machine, while the rest is the processor architecture, processor type, version, speed and operating system information.
You can also use the -a option which prints out all the available information about the kernel and the machine.
Type the following command to see kernel version and gcc version used to build the same:
$ cat /proc/version

List all Users:

$ cat /etc/passwd
$ more /etc/passwd
$ less /etc/passwd
$ awk -F':' '{ print $1}' /etc/passwd

A Note About System and General Users: Each user has numerical user ID called UID. It is defined in /etc/passwd file. The UID for each user is automatically selected using /etc/login.defs file when you use useradd command. To see current value, enter:
$ grep "^UID_MIN" /etc/login.defs
$ grep UID_MIN /etc/login.defs

1000 is minimum values for automatic uid selection in useradd command. In other words all normal system users must have UID >= 1000 and only those users are allowed to login into system if shell is bash/csh/tcsh/ksh etc as defined /etc/shells file. Type the following command to list all login users:
## get UID limit ##
l=$(grep "^UID_MIN" /etc/login.defs)
## use awk to print if UID >= $UID_LIMIT ##
awk -F':' -v "limit=${l##UID_MIN}" '{ if ( $3 >= limit ) print $1}' /etc/passwd

To see maximum values for automatic uid selection in useradd command, enter:
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max ) print $0}' /etc/passwd
$ grep "^UID_MAX" /etc/login.defs

In other words all normal system users must have UID >= 1000 (MIN) and UID <= 60000 (MAX) and only those users are allowed to login into system if shell is bash/csh/tcsh/ksh etc as defined /etc/shells file. Here is an updated code:
## get mini UID limit ##
l=$(grep "^UID_MIN" /etc/login.defs)
## get max UID limit ##
l1=$(grep "^UID_MAX" /etc/login.defs)
## use awk to print if UID >= $MIN and UID <= $MAX   ##
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max ) print $0}' /etc/passwd

/sbin/nologin is used to politely refuse a login i.e. /sbin/nologin displays a message that an account is not available and exits non-zero. It is intended as a replacement shell field for accounts that have been disabled or you do not want user to login into system using ssh. To filter /sbin/nologin, enter:
#!/bin/bash
# Name: listusers.bash
# Purpose: List all normal user accounts in the system. Tested on RHEL / Debian Linux
# Author: Vivek Gite <www.cyberciti.biz>, under GPL v2.0+
# -----------------------------------------------------------------------------------
_l="/etc/login.defs"
_p="/etc/passwd"
## get mini UID limit ##
l=$(grep "^UID_MIN" $_l)
## get max UID limit ##
l1=$(grep "^UID_MAX" $_l)
## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin   ##
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max  && $7 != "/sbin/nologin" ) "$_p"

Finally, this script lists both system and users accounts:
#!/bin/bash
# Name: listusers.bash
# Purpose: List all normal user and system accounts in the system. Tested on RHEL / Debian Linux
# Author: Vivek Gite <www.cyberciti.biz>, under GPL v2.0+
# -----------------------------------------------------------------------------------
_l="/etc/login.defs"
_p="/etc/passwd"
## get mini UID limit ##
l=$(grep "^UID_MIN" $_l)
## get max UID limit ##
l1=$(grep "^UID_MAX" $_l)
## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin   ##
echo "----------[ Normal User Accounts ]---------------"
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max  && $7 != "/sbin/nologin" ) print $0 }' "$_p"
echo ""
echo "----------[ System User Accounts ]---------------"
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( !($3 >= min && $3 <= max  && $7 != "/sbin/nologin")) print $0 }' "$_p"

Get Current User:

a] $USER - Current user name. 
$ echo "$USER"
u="$USER"
echo "User name $u"
b] $USERNAME - Current user name.
c] id command - Current user name.[$ id -u -n]
#!/bin/bash
_user="$(id -u -n)"
_uid="$(id -u)"
echo "User name : $_user"
echo "User name ID (UID) : $_uid"
- - - - - - - - - - - - - - - - - - - - - - - 
# Make sure only root user can run the following script:
#!/bin/bash 
## get UID 
uid=$(id -u)
## Check for it
[ $uid -ne 0 ] && { echo "Only root may enable the nginx-chroot environment to the system."; exit 1; }
## Continue main logic with root user
- - - - - - - - - - - - - - - - - - - - - -
A note about $EUID:This variable EUID is readonly. It expands to the effective user ID of the current user, initialized at shell startup. You can use $EUID to find out if user is root or not with the following syntax:
# Find out if you are root or not for admin tasks.
(( EUID )) && { echo 'Run this script with root priviliges.'; exit 1; } || echo 'Running as root, starting service...'

Add Group & User:

You can use the useradd or usermod commands to add a user to a group. The useradd command creates a new user or update default new user information. The usermod command modifies a user account and it is useful to add user to existing groups. There are two types of groups under Linux operating systems:
  1. Primary user group.
  2. Secondary or supplementary user group.
All user account related information are stored in the following files:
  • /etc/passwd - Contains one line for each user account.
  • /etc/shadow - Contains the password information in encrypted formatfor the system's accounts and optional account aging information.
  • /etc/group - Defines the groups on the system.
  • /etc/default/useradd - This file contains a value for the default group, if none is specified by the useradd command.
  • /etc/login.defs - This file defines the site-specific configuration for the shadow password suite stored in /etc/shadow file.
You need to the useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. The syntax is as follows:
# useradd -G {group-name} username
$ grep developers /etc/group # make sure developers group exists, or add developers Group
# If you do not see any output then you need to add group developers using the groupadd command:
$ groupadd developers
# Next, add a user called dixit to group developers:
$ useradd -G developers dixit
# Setup password for user dixit:
$ passwd dixit
# Ensure that user added properly to group developers:
$ id dixit
# Output: uid=1122(dixit) gid=1125(dixit) groups=1125(dixit),1124(developers)
# Please note that capital G (-G) option add user to a list of supplementary groups.
$ useradd -G admins,ftp,www,developers dixit
# Add existing user dixit to ftp supplementary/secondary group with the usermod command using the -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:
$ usermod -a -G ftp dixit
# In this example, change tony user's primary group to www, enter:
$ usermod -g www dixit


Option                          Purpose
-a
--append                 Add the user to the supplementary group(s). Use only with the -G option.
-g GROUP
--gid GROUP                 Use this GROUP as the default group.
-G GRP1,GRP2
--groups GRP1,GRP2 Add the user to GRP1,GRP2 secondary group.

Give Sudo Access to User

Run visudo as root and add following line:
dixit ALL = (root) ALL # this line give sudo access to root for user 'dixit'.
dixit ALL = (root) /bin/kill, /bin/ps # this line give root access to user 'dixit'.
#### Root user spec - following line give all access to user 'root'.
root ALL = (ALL) ALL

Edit /etc/sudoers file either manually or using visudo application. Remember: System reads /etc/sudoers file from top to the bottom, so you could overwrite particular setting by putting next one below. So to be on the safe side - define your access setting at the bottom.
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
#includedir /etc/sudoers.d
To add a user to the group you should run (as root):
# usermod -a -G groupname username
where groupname is your group (developers, admin) and username is the username (eepuser, dixit).

# Find occurrence of word in a file:
$ grep -c word file # [grep -c 'java.util.ConcurrentModificationException' ddp-mediation-ms-ddp-po-3p.log*]
$ grep -ic word file # case insensitive

# Count multiple occurrences of the word in a single line:
$ cat filename | grep -o 'word' | wc -l
$ cat ddp-mediation-rte_ddp_1_1.log | grep -o '201402090032218553' | wc -l
$ cat ddp-mediation-rte_ddp_1_1.log | grep -o 'INFO' | wc -l

# Find line number in a text file - without opening the file:
$ grep -C 2 yourSearch yourFile
$ grep -C 2 yourSearch yourFile > result.txt

# $ grep -n -2 your_searched_for_string  your_large_text_file
Will give you almost what you expect
-n : tells grep to print the line number
-2 : print 2 additional lines (and the wanted string, of course)