Centralizing user shell history files (.sh_history)

Centralizing user shell history files (.sh_history) and enabling Date/Time Stamp on user shell history.

Detail Description of change:

1. Add the following entry to /etc/profile to save all users history file in a central location.
mkdir /var/adm/hist/; chmod 1777 /var/adm/hist/;
export HISTFILE=/etc/hist/.hist-$LOGNAME

##################################################
#User shell history centralization – [14092011-150500]

export HISTSIZE=10000
export HISTFILE=/var/adm/hist/.hist-$LOGNAME
typeset -r HISTSIZE
typeset -r HISTFILE
##################################################

Note:- Use of “typeset” to make those env. variables read-only and to stop being overridden by the users shell startup files.

2. Adding the following entry to /etc/environment to enable Data/Time Stamp on shell history.
EXTENDED_HISTORY=ON

###############
How This Works
###############
Each unix user’s shell history file will be created under “/var/adm/hist/”.

To view any user’s command history:
#su – <username> -c fc -t
============================================================
For bash, the EXTENDED_HISTORY variable is not supported, so you will have to set the HISTTIMEFORMAT variable to something as follows:

# HISTTIMEFORMAT=”%h/%m – %H:%M:%S ”

Now, when you run the history command, you will have the timestamp in bash.
Example:- export EXTENDED_HISTORY=ON; history; fc -t
============================================================

References
http://www.coolcommands.com/index.php?option=com_cc&task=display&id=1184
http://unix.ittoolbox.com/groups/technical-functional/ibm-aix-l/is-there-a-way-we-could-log-all-commands-executed-by-any-users-on-an-aix-server-4363412

============================================================

Following shell session will demonstrate the operation.
root@nim01:/>cd /var/adm/hist/
root@nim01:/var/adm/hist>pwd
/var/adm/hist
root@nim01:/var/adm/hist>ls -a
.              ..             .hist-ibmuser  .hist-root     .hist-sp2280
root@nim01:/var/adm/hist>ls -l .hist-*
-rw——-    1 ibmuser  staff           284 Dec 15 10:06 .hist-ibmuser
-rw——-    1 root     system        60488 Dec 15 10:06 .hist-root
-rw——-    1 sp2280   staff           270 Dec 14 13:05 .hist-sp2280
root@nim01:/var/adm/hist>cd ~
root@nim01:/>su – sp2280 -c fc -t
1       2011/12/14 13:04:23 :: alias
2       2011/12/14 13:04:32 :: echo $HISTFILE
3       2011/12/14 13:04:37 :: bash
4       ? :: ifconfig -a
exit
5       2011/12/14 13:04:43 :: df -g
6       2011/12/14 13:04:50 :: cd /var/adm/hist
7       2011/12/14 13:04:55 :: ls -a
8       2011/12/14 13:05:03 :: cat .hist-sp2280
9       2011/12/14 13:05:09 :: cd ~
10      2011/12/14 13:05:13 :: exit
root@nim01:/>
============================================================

NOTE:- This has been tested under IBM AIX environment, but should be able to applied to rest of the UNIX flavors including Linux with little or no change at all.

Categories: Uncategorized

Mayonnaise jar and 2 cups of coffee

When things in your life seem almost too much to handle and When 24 hours in a day is not enough;
Remember the mayonnaise jar and 2 cups of coffee.

A professor stood before his philosophy class and had some items in front of him. When the class began, wordlessly, he picked up a very large and empty mayonnaise jar and started to fill it with golf balls.

He then asked the students if the jar was full.. They all agreed that it was.

The professor then picked up a box of pebbles and poured it into the jar. He shook the jar lightly. The pebbles rolled into the open areas between the golf balls.

He then asked the students again if the jar was full. They agreed it was.

The professor next picked up a box of sand and poured it into the jar. Of course, the sand filled up everything else.
He asked once more if the jar was full. The students responded with a unanimous ‘yes.’

The professor then produced two cups of coffee from under the table and poured the entire contents into the jar, effectively filling the empty space between the sand. The students laughed.

‘Now,’ said the professor, as the laughter subsided, ‘I want you to recognize that this jar represents your life.

The golf balls are the important things – God, family, children, health, friends, and favorite passions. Things that if everything else was lost and only they remained, your life would still be full.

The pebbles are the things that matter like your job, house, and car.

The sand is everything else — The small stuff.

‘If you put the sand into the jar first,’ he continued, ‘there is no room for the pebbles or the golf balls. The same goes for life.

If you spend all your time and energy on the small stuff, You will never have room for the things that are important to you.

So…

Pay attention to the things that are critical to your happiness. Play with your children. Take time to get medical checkups. Take your partner out to dinner.

There will always be time to clean the house and fix the dripping tap.

‘Take care of the golf balls first — The things that really matter. Set your priorities. The rest is just sand.’

One of the students raised her hand and inquired what the coffee represented.

The professor smiled. ‘I’m glad you asked’.

It just goes to show you that no matter how full your life may seem, there’s always room for a couple of cups of coffee with a friend.’

Categories: Like

signal 11 caught by ps | segmentation fault

November 15, 2009 1 comment

If you ever came across “segmentation fault” message in linux [in my case CentOS/RHEL], you know how annoying it can be. Basically it throws every time you invoke “ps | top | killall” – i.e any process related command.
Googleing gave me couple of tips. cyberciti, took my attention.

Since “ps” started to gave me the trouble, i decided to upgrade the “ps”

“ps” comes under a package, so fist i had to locate the package name which provide “ps”.
For that again i had to locate the “ps” executable :-
[root@server1 ~]# whereis ps
ps: /bin/ps /opt/mandriva_root/bin/ps /usr/share/man/man1p/ps.1p.gz

Then i locate the package name :-
[root@server1 ~]# rpm -qf /bin/ps
procps-3.2.7-11.1.el5

The procps package contains a set of system utilities that provide system information.

To update “procps” :-
[root@server1 ~]# yum update procps

“procps” update did the trick for me.

BR.

Categories: Linux

Little help on Perl

September 28, 2009 Leave a comment

What is Perl?

From the Perl documentation:

Perl is a high-level programming language with an eclectic heritage written by Larry Wall and a cast of thousands. It derives from the ubiquitous C programming language and to a lesser extent from sed, awk, the Unix shell, and at least a dozen other tools and languages. Perl’s process, file, and text manipulation facilities make it particularly well-suited for tasks involving quick prototyping, system utilities, software tools, system management tasks, database access, graphical programming, networking, and world wide web programming. These strengths make it especially popular with system administrators and CGI script authors, but mathematicians, geneticists, journalists, and even managers also use Perl. Maybe you should, too.

  • Get the Perl manual.
    • [root@goliath ~]# man perl
  • View Perl documentation.
    • [root@goliath ~]# man perldoc
  • Perl introduction for beginners.
    • [root@goliath ~]# perldoc perlintro
  • Perl OO tutorial for beginners.
    • [root@goliath ~]# perldoc perlboot
  • Perl OO tutorial, part 1.
    • [root@goliath ~]# perldoc perltoot
  • Perl OO tutorial, part 2.
    • [root@goliath ~]# perldoc perltooc
  • Perl OO tricks and examples.
    • [root@goliath ~]# perldoc perlbot
  • Perl regular expressions quick start.
    • [root@goliath ~]# perldoc perlrequick
  • Perl regular expressions tutorial.
    • [root@goliath ~]# perldoc perlretut
  • List the modules that come pre-installed with the standard Perl package.
    • [root@goliath ~]# perldoc perlmodlib
  • Lists the optional modules that are installed in your system that don’t come with Perl by default.
    • [root@goliath ~]# perldoc perllocal
  • Check if a module is installed
    • [root@goliath ~]# perl -MTie::Hash -e 1
  • Get a list of installed modules – Using a script
    • [root@goliath ~]# perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e ‘find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC’

CPAN
CPAN is the Comprehensive Perl Archive Network, a large collection of Perl software and documentation. Note that CPAN is also the name of a Perl module, CPAN.pm, which is used to download and install Perl software from the CPAN archive.
Reference – http://www.cpan.org/

  • Automatic installation using the CPAN module
    • [root@goliath ~]# perl -MCPAN -e ‘install Net::DNS’
  • Installing cpan modules manually
    • unzip
    • perl Makefile.PL
    • make
    • make test
    • make install

Hope thses tip’s will help you to get on with perl.

Categories: Linux

Some book’s i value most

Here’s some of the books .. i simply can’t live with out …

  • Red Hat Certified Engineer Linux Study Guide – Michael Jang
  • Linux Administration Handbook – Evi Nemeth , Garth Snyder , Trent R. Hein
  • Open Source Web Development with LAMP – James Lee , Brent Ware
  • Using Unix – Peter Kuo
  • Beginning PHP5,Apache and MySQL Web Development – Elizabeth Naramore , Jason Gerner , Yann Le Scouarnec , Jeremy Stolz , Michael K. Glass
Categories: Linux

Vote for OrangeHRM here !

Love this application. It’s FREE and It’s open source.

Categories: Linux

Create RHEL/CentOS Boot Disk

Floppies no longer supported in RHEL/CentOS-5. So you need to create boot CD/DVD.

  • Put the RHEL/CentOS-5 DVD/first CD to CDROM/DVDROM -> mount the device.

IF you CD/DVD not get automount ->

  • First find the device -> dmesg | grep -i dvdrom -> then
  • mount the device -> mount /dev/device /mnt/destination

Locate the <images> directory from the CD/DVD contents. Get burn <boot.iso> image to CD/DVD. You can use either k3b OR cdrecord to get this done.

🙂

Categories: Linux

NFS kickstart installation

Installing Linux includes several steps. Installation will take some time depending on the number of packages you have selected. If you installing Linux to a single machine, then it’s no big deal. But if you have to perform installation on several machines, then the process is cumbersome.

So the solution is to have a installation server. We discuss in a previous post the setup steps involves in a NFS , FTP installation server. There you boot from a installation media and select installation method, then installation will start. But still need to go through all the installation steps. So in order to make life easy we can make the installation automated by the use of kickstart installation provided by RHEL/CentOS.

To start with kickstart. Invoke “system-config-kickstart” (shell) OR Applications->System Tools->Kickstart
If don’t have kickstart already installed, get it installed.

  • yum -y install system-config-kickstart

Fill all the necessary fields. Save the changes. Place it some where with in the reach of NFS. Let’s say, /var/ftp/pub/ks.cfg
/var/ftp/pub/ -> should be a exported file system by now.

  • showmount -e hostname -> will list the nfs shares of hostname.

Now you ready to start the installation. Boot the system from the boot DVD/CD. In the boot prompt, type :-

  • boot:linux ks=nfs:10.0.0.1:/var/ftp/pub/ks.cfg

Press Enter.System should get on with the installation.  CHEERS 🙂

NOTE :- IP addresses used here are belong to IPV4 private ranges.Replace it with your’s.

Categories: Linux

RHEL/CentOS FTP Installation

As the first step of creating FTP installation server, create a directory under /var/ftp/pub. Let say CentOS-5.2. Copy all CD/DVD contents to the created directory.

  • mkdir -p /var/ftp/pub/CentOS-5.2

Then locate vsftpd configuration file.

  • vim /etc/vsftpd/vsftpd.conf – There …..

anonymous_enable=YES -> will give anonymous access to vsftp
local_enable=YES -> will allow access to local user’s
xferlog_file=/var/log/vsftpd.log -> will create separate log file for vsftp. Once done save the file.

  • service vsftpd restart -> will restart the vsftd service. vsftpd set up should be OK by now.

Next boot the system from boot CD/DVD. Select the Language , keyboard , installation method. Choose FTP for the installation method. Choose static OR DHCP under TCP/IP configuration.

NOTE :- If you choosing DHCP, you should have DHCP server in place already. I will be discussing steps involved in a DHCP server setup in a separate post. So watch out. 🙂

Under the FTP setup ->
FTP site name:10.0.0.1 – type the IP address of the server.
ftp://10.0.0.1 -> WRONG FORMAT
CentOS/RHEL directory:pub/CentOS-5.2 – give the path relative to the /var/ftp directory
/var/ftp/pub/CentOS-5.2 -> WRONG FORMAT

In the vsftp.conf if you have set -> anonymous_enable=NO
Then in the FTP setup, check the “Use non-anonymous ftp” and provide the authentication information for the user.

If everything went right system should start the installation by now.  🙂

Categories: Linux

RHEL/CentOS NFS installation

To set up NFS installation server, first locate and edit /etc/exports with the preferred NFS path.

  • vim /etc/exports -> put the path. Let say, /var/ftp/pub/CentOS-5.2

NOTE :- For file editing you can use your favorite file editor. In this case I’m using “vim”, which I’m very much comfortable with. In your case it might be some thing else. Can be either nano , emacs OR gedit. If you newbie, then I’m recommending vim for you.

TO GET START WITH VIM, Type “vimtutor” in your shell. The Vim tutor.

Back on NFS again…..

  • exportfs -ua -> will umount all exported file systems
  • exportfs -ra -> will remount all exported file systems
  • showmount -e hostname -> will list all exported file systems in hostname

If iptables ON, nfs probably won’t work. Most probably your nfs ports must be blocked by firewall. First clarify whether the firewall is turned on OR off in you machine.

  • service iptables status – will give the iptables status

If iptables turned on, then get a list of applied iptables rules. To do so,

  • iptables -L | less – will list current iptables rules.

If you see four strings in the below format, probably nfs might work over the firewall for you.

iptables -A INPUT -s 192.x.x.x/24 -p tcp –dport 111 -j ACCEPT
iptables -A INPUT -s 192.x.x.x/24 -p udp –dport 111 -j ACCEPT
iptables -A INPUT -s 192.x.x.x/24 -p tcp –dport 2049 -j ACCEPT
iptables -A INPUT -s 192.x.x.x/24 -p udp –dport 2049 -j ACCEPT
NOTE :- IP addresses used here are belong to IPV4 private ranges. Replace it with yours.

If not we need to allow nfs over iptables. To allow NFS over iptables :-

  • iptables -A INPUT -j ACCEPT

NOTE :- More general rule that will allow all incoming traffic through the firewall. Later I’ll discuss nfs over firewall in much detail in some other post.

  • service iptables save; restorecon -R /etc/sysconfig/* – will save iptables settings and restore selinux context.
  • service iptables restart.

nfs should be OK over iptables by now. Let’s get start the installation.

Start system with the help of the boot CD/DVD. In the boot: prompt, Either you can press enter and go ahead with booting the system, which later prompt for the installation method OR Press F2 and go to options and invoke “linux askmethod”. In each you’ll be asked to select language , keyboard , and installation method. Select “NFS” for installation method.

To Configure TCP/IP, you can use either static IP or DHCP. If you have DCHP server in place use DHCP or use a correct static IP.

NOTE :- you will find DHCP settings in a up coming post.

In NFS setup ->

under the nfs server name : use name OR IP of the NFS server
under the CentOS/RHEL directory : /use/correct/path/

If everything went right system should start the installation. 🙂

Categories: Linux