Tuesday, January 22, 2013

History command With Date and Time In Linux.

Add the line at end of file.

[root@neonserv ~]# vi  /etc/bashrc

# vim:ts=4:sw=4
test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local

Create one file name  "/etc/bash.bashrc.local"  and edit like as follows.

[root@neonserv ~]# vi /etc/bash.bashrc.local

#local bashrc mods
# turn on date time stamps in history
export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
export HISTCONTROL=ignoreboth
export HISTSIZE=2000

So when you will fire command output will be like this:
[root@neonserv ~]# history
 1033  Jan/22 - 15:30:44 accton
 1034  Jan/22 - 15:31:16 /etc/init.d/psacct start
 1040  Jan/22 - 15:32:06 lastcomm shrii
 1041  Jan/22 - 15:32:10 lastcomm root
 1042  Jan/22 - 15:32:38 lastcomm
 1043  Jan/22 - 15:32:48 lastcomm rm
 1044  Jan/22 - 15:32:51 lastcomm ls
 1045  Jan/22 - 15:32:53 lastcomm root
 1050  Jan/22 - 21:49:44 history

Monday, January 21, 2013

How To Lock/Unlock and Check The User In Linux.

## You can use this command to lock the User: shrii.

[root@localhost ~]# passwd -l shrii
Locking password for user shrii.
passwd: Success

##  This command shows you particular user status. If it is locked or unlock.

[root@localhost ~]# passwd -S shrii
shrii PS 2013-01-21 0 99999 7 -1 (Password set, MD5 crypt.)

## Using this command it will give you list.
[root@localhost ~]# cat /etc/passwd | cut -d : -f 1 | awk '{ system("passwd -S " $0) }' 

test PS 2012-12-27 0 99999 7 -1 (Password set, MD5 crypt.)
shrii PS 2013-01-21 0 99999 7 -1 (Password set, MD5 crypt.)
shrikant LK 2013-01-21 0 99999 7 -1 (Password locked.)
yo LK 2013-01-21 0 99999 7 -1 (Password locked.)

## Using the -u option you can unlock the user.
[root@localhost ~]# passwd -u shrii
Unlocking password for user shrii.
passwd: Success.

####### Another way to lock/unlock the user is "usermod".

## For Locking user.

usermod -L username

## for Unlocking the user.
usermod -U username

Friday, January 18, 2013

One Click Centralized Application Deployment With Webistrano.

One Click Centralized Application Deployment With Webistrano.

We mostly heard the name Hudson, Jenkin, Bamboo, etc. when we talk about application deployment. 

And above all mostly use for Java (For Continuous Integration). 
So what for Ruby on Rails, PHP, Wordpress, Magento, etc. yes we have best option and that is Webistrano. 
Its Open source and stable tool and if you utilize it properly for Application deployment you can have peace of mind and good sleep :) which is rare in this days. 
The back-end of Webistrano is most famous Capistrano. So yes its bug-less and rocking.

- User friendly and simple to use.

- Remote Multi-host deployment.
- One click and Centralize. 
- We can create Custom Recipes. 
- Much secure. 
- Deploy option with SVN and Git. 
- User Management. 
- Access Management. Limited Access for Developers who deploying application.
- Rollback option available. 
- you can deploy unlimited project in it. Same for Recipes, Host, Users.
- Its keeps history that no one can delete any more. 
- Interactive Deployment. So you can see and check the log what happening. 
- You can manage Min-Max Releases. 
- Failed build will never deploy on any server it just keep in history.
- Developers do not need to login to server any more. You can add task(recipes) for 
   checking logs Application and Apache etc. 
- Ready made default task available for Ruby on Rails.


- Project Wise Access. 
- Stage wise access available.  If you have Stage Environment Prod, Stage and Dev. You can 
  give access by stage wise. 
  Like:  For System admin – Prod.
            For Developers - Stage and Dev. 
- Read only Access also available for user.

Custom Recipes:
- You can add the Trigger After and Before deploy.

- It create the revision of recipes. So if we need older recipes we can have that any time in our
- If you have same environment for Staging, Production, Development you can use only one 
   recipe for all, No need to create individual recipes for each Stage. 

Manage Maintenance Page:
- By default there is recipes/task web-enable and web-disable 
   which is same Capistrano.
- You need to just made necessary entries is Apache Virtual Config and just run the task. 
- So you can add the web enable and web disable task in After and Before Trigger.
   So that it will run After and Before deployment.

Tips: If you using Capistrano you should try Webistrano and feel the Fun choose more  

Thursday, January 17, 2013

rc.local script in Opensuse 11.

If you have commands and you wanted that while boot. In RHEL/CENTOS /etc/rc.d/rc.local but the same file is not exists in Opensue by default you have to create that using following steps.

Create the file  /etc/rc.d/rclocal
# file content #! /bin/sh

## This script simulates redhat's rc.local (Add commands at the end)

# Provides: rclocal
# Required-Start: $local_fs $remote_fs $network
# X-UnitedLinux-Should-Start: $ALL
# Required-Stop:
# X-UnitedLinux-Should-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Simulates rc.local
# Description: Simulates redhat's rc.local: contains
# commands to execute after system has booted (all services are already
# available)

## Execute ony when service is started
case "$1" in
## commands will be executed
exit 0

Do give right permission for executable using command : chmod 777 /etc/rc.d/rclocal
Create symlink if you want ln -s  /etc/rc.d/rclocal  /etc/rc.d/rc.local

You have to Enable that service in Yast2 from command prompt, using this command.

yast2 > System > Runlevel editor > rclocal > Enable
Now you can edit file  /etc/rc.d/rc.local  add your command in script at "case $1".

Reboot and check..! Its done.!

Wednesday, January 16, 2013

Error reading block 2851259 (Invalid argument) while doing inode scan. Ignore error? yes Force rewrite? yes

If you are facing following error while shrink LVM using lvreduce command.

Error reading block 2851259 (Invalid argument) while doing inode scan.  Ignore error? yes
Force rewrite? yes

It  means  if you trying to reduce the lvm partition the partition may be corrupt.
So you can do this step by step. 

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/data--vg-data    14G  154M   13G   2% /data

## If you reduceing the LVM 4GB you using.
 lvreduce -L -4G /dev/data-vg/data

[root@localhost ~]# e2fsck -f /dev/data-vg/data
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
The filesystem size (according to the superblock) is 3670016 blocks
The physical size of the device is 2621440 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort? yes

## Extend LVM with the original size.
lvextend -L+4G /dev/mapper/data--vg-data

## Recheck the Partition.
e2fsck -f /dev/data-vg/data
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/data-vg/data: 18/1835008 files (5.6% non-contiguous), 96794/3670016 blocks

### Try to resize again.
[root@localhost ~]# resize2fs -p /dev/mapper/data--vg-data
resize2fs 1.39 (29-May-2006)
The filesystem is already 3670016 blocks long.  Nothing to do!

## mount that filesystem.
[root@localhost ~]# mount /dev/data-vg/data /data/

### check again.
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/data--vg-data    14G  154M   13G   2% /data

### Take a backup of data with snapshot (create snapshot with minimum size of data.) and mount to
##  system.

[root@localhost /]# lvcreate -L9G  -s  -n snap-data /dev/data-vg/data
  Logical volume "snap-data" created
[root@localhost /]# mount /dev/data-vg/snap-data /snap/
[root@localhost /]# df /snap/
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/data--vg-snap--data          14449712    156824  13558888   2% /snap
[root@localhost /]# cd /snap/
[root@localhost snap]# ls -la
total 60
drwxr-xr-x  4 root root  4096 Jan 16 16:38 .
drwxr-xr-x 34 root root  4096 Jan  7 18:22 ..
-rw-r--r--  1 root root    21 Jan 16 16:37 file
-rw-r--r--  1 root root    21 Jan 16 16:38 file1
-rw-r--r--  1 root root    21 Jan 16 16:38 file2
drwx------  2 root root 16384 Jan 16 16:34 lost+found
drwxr-xr-x  2 root root  4096 Jan 16 16:39 yo

### Now you can umount data partition and reduce the original  "data" partition, remount the /data and move the snapshot backup to /data partition.

Guys, any query please let me know.