Friday, October 7, 2011

HMC vtmenu exit

You can exit the cosole of an LPAR ,that has been taken using HMC vtmenu ,by typing
"~." (press dot key after tild without qoutes )

If you had taken HMC vtmenu using SSH ,your ssh connection to HMC will alse loses.

Friday, September 23, 2011

Read /etc/passwd using TFTP venerability - How to resolve in AIX

1.vi /etc/tftpaccess.ctl
allow:/tftpboot

Save the file
You are done..!!!
Now the clients can only access /tftpboot using TFTP


Monday, August 29, 2011

FTP Banner in AIX

1.vi /etc/ftpaccess.ctl

herald: /path/to/banner/file ---->Enter your welcome message in this file
motd: on

2.refresh -s inted


You are done



Friday, August 19, 2011

DRBD on RHEL6 with YUM group



Building DRBD for 2.6.32-71.el6.x86_64 kernel

1.mkdir -p /root/rpmbuild/SOURCES/

2.wget http://oss.linbit.com/drbd/8.3/drbd-8.3.10.tar.gz

3.cp drbd-8.3.10.tar.gz /root/rpmbuild/SOURCES/

4.tar -xvf drbd-8.3.10.tar.gz

5.cd drbd-8.3.10

6../configure --with-km --with-distro=redhat --enable-spec

7.rpmbuild -bb drbd.spec

8.rpmbuild -bb drbd-km.spec

9.cd /root/rpmbuild/RPMS/x86_64

10.mkdir /YUM/DiskReplicator

11.cp drbd-* /YUM/DiskReplicator/

12.cd /YUM/DiskReplicator/

13.createrepo . ---> The "." is important


14.vi /etc/yum.repos.d/rhel6-1.repo


[DiskReplicator]
name=rhel6-1 LoadBalancer repo
baseurl=ftp://192.168.8.2/DiskReplicator
enabled=1
gpgcheck=0

15.cd /tmp/ -->To avoid rpm name clash

16.yum install yum-utils

17.yum-groups-manager -n "Disk Replicator" --id=drbd --description="DRBD, packages from ANSIL" --save=comps.xml --mandatory drbd.x86_64 --mandatory drbd-bash-completion.x86_64 --mandatory drbd-heartbeat.x86_64 --mandatory drbd-km-2.6.32_71.el6.x86_64.x86_64 --mandatory drbd-pacemaker.x86_64 --mandatory drbd-udev.x86_64 --mandatory drbd-utils.x86_64 --mandatory drbd-xen.x86_64


18.createrepo -g comps.xml /YUM/DiskReplicator/

19.yum grouplist "Disk Replicator"

20.yum groupinstall "Disk Replicator"

Monday, August 15, 2011

How to Configure YUM in RHEL6

Easy way to create your own repo
1. Put your RHEL6 media on DVD drive
2. Create a partition with size 6GB and mount it as /yum
3. Download the below script to /yum
https://sites.google.com/site/ansilh/rhel6_repo.sh
4. Give execute permission to the downloaded script
5. Please open the file and try to understand it. If you found all safe ,then go to next step
6. Execute it...You will get an RHEL repo accessible through ftp


***Please feel free to comment your experience ***

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

Manual Steps (*Different approach from above script .The repo file not look like usual one)

YouTube Link : http://www.youtube.com/watch?v=scBtTTwLze0
 
1.create a directory to store packages .(Better you create a partition with 5GB size and mount it as /YUM)
mkdir /YUM
2.mount RHEL6 DVD
mount /dev/dvd /mnt
3.go to the mounted directory
cd /mnt/Packages/
4.copy all contents of DVD to /YUM (Note the "." in command )
cp . /YUM/
5.Install createrepo package with dependancies
rpm -ivh deltarpm-**.el6.x86_64.rpm python-deltarpm-**.el6.x86_64.rpm createrepo-**.rpm
6.install FTP server
rpm -ivh vsftpd-2.2.2-6.el6.x86_64.rpm
7.Create repository using
createrepo -g /YUM/HighAvailability/repodata/****-comps-rhel6-HighAvailability.xml –o \
/YUM/HighAvailability/ /YUM/Packages/

createrepo -g /YUM/LoadBalancer/repodata/*****-comps-rhel6-LoadBalancer.xml –o \
 /YUM/LoadBalancer/ /YUM/Packages/

createrepo -g /YUM/ResilientStorage/repodata/****-comps-rhel6-ResilientStorage.xml –o  \
 /YUM/ResilientStorage/ /YUM/Packages/

createrepo -g /YUM/ScalableFileSystem/repodata/****-comps-rhel6-ScalableFileSystem.xml –o \
 /YUM/ScalableFileSystem/ /YUM/Packages/

createrepo -g /YUM/Server/repodata/****-comps-rhel6-Server.xml -o /YUM/Server/ /YUM/Packages/
8.Create a repo file in /etc/yum.repos.d/

The Server id contains the main path to the packages.(bold in [Server] baseurl )

vi /etc/yum.repos.d/rhel6-1.repo
[Server]
name=rhel6-1 Server repo
baseurl=ftp://192.168.8.2/Server
              ftp://192.168.8.2/Packages
enabled=1
gpgcheck=0
[HighAvailability]
name=rhel6-1 HighAvailability repo
baseurl=ftp://192.168.8.2/HighAvailability
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=rhel6-1 ScalableFileSystem repo
baseurl=ftp://192.168.8.2/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=rhel6-1 ResilientStorage repo
baseurl=ftp://192.168.8.2/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=rhel6-1 LoadBalancer repo
baseurl=ftp://192.168.8.2/LoadBalancer
enabled=1
gpgcheck=0
9.Edit ftp server configuration file to make /YUM as anonymous root
vi /etc/vsftpd/vsftpd.conf 
anon_root=/YUM
10.Restart ftp service
service vsftpd restart
11.Add a rule in iptables to accept ftp connections in /etc/sysconfig/iptables
vi /etc/sysconfig/iptables
-A INPUT -p tcp -s 192.168.8.0/24 --dport 21 -i eth0 -j ACCEPT

12.Add ip_conntrack_ftp module in /etc/sysconfig/iptables-config which is needs to be added for FTP support[ip_nat_ftp]

vi /etc/sysconfig/iptables-config
IPTABLES_MODULES="ip_conntrack_ftp" 
service iptables restart
13.Install the following packages[both clients and server need these packages] to transfer files
You need to install it from DVD
Follow step 2 and 3 and then
rpm -ivh libedit-2.11-4.20080712cvs.1.el6.x86_64 openssh-clients-5.3p1-20.el6.x86_64 ftp-0.17-51.1.el6.x86_64.rpm
14.transfer yum configuraion files to clients

scp /etc/yum.repos.d/rhel6-1.repo *.*.*.*:/etc/yum.repos.d/
15.Check yum configuratoin

yum grouplist will give you these ouputs

Installed Groups:
E-mail server
FTP server
Available Groups:
Additional Development
Afrikaans Support

...

Enjoy RHEL6 Package Management

I've made a video for easy understanding

http://www.youtube.com/watch?v=scBtTTwLze0

Friday, May 6, 2011

MySQL backup script

This script is made using dialogues
So without dialogue package it will not work

You can start a mysql instance in full customized way

The script is mainly focused on MySQL compiled from source code

The script is using a config file to get necessary information to store values like

path to mysql daemon ,myql dump,mysql safe ,user name and password to start mysql instance

You can download the script from the following link

The advantage is ,You can take the entire database as well as a particular table of a schema using this script.


https://sites.google.com/site/ansilh/mysql-backup-script/mybackup.sh

Monday, April 25, 2011

Screen saver using script / CLI screen saver

Can you imagine we can make animations using shell script..?

Yes ...Here is one I made screen.sh
A floating box in CLI with my name inside

You can execute the script in any row - column resolution
You can re-size the window if you are accessing system using PuTTy(little bit disturbance if you are resizing from large to small window but it will stabilize after few seconds)

The script is released under GNU public license

Download it from here

https://sites.google.com/site/ansilh/screen.sh


Try and post your comments

Wednesday, April 20, 2011

Terminal input output logger / Teminal recording

Logging terminal input and output
------------------------------------------

After a lot of googling I found a tool that can log all input and output of terminal in Unix system

The tool is rootsh and its not only used for logging but also used for root login for normal users using sudo.

So that the command entered by the user will be logged in a file as well as on syslog

We can make rootsh as a shell , So that all the activity by that particular user will be logged

The tool is released under GNU Open source license

You can download the tool from

http://sourceforge.net/projects/rootsh/

I made a modified copy of mine on
https://sites.google.com/site/ansilh/rootsh

The tool will log username,commands and its output in a file -- But no client IP
The command can be started as a shell -But it will take the default shell

I made some modification on this and it's working perfectly on my Linux machine
The link here

https://sites.google.com/site/ansilh/rootsh/rootsh-1.5.3-final.tar.gz

The extra modules I added are here
username.c --->This will challenge the user to enter actual name of user and
purpose of login
https://sites.google.com/site/ansilh/rootsh/username.c

readconf.c ----->This will read configuration file /etc/rootsh.conf
format of the file will be

:
e.g
ansil:/bin/bash

do not add space on end of the line (need some code changes)
https://sites.google.com/site/ansilh/rootsh/readconf.c

Keep an eye on here ..more to come like remote logging with TLS security on a separate file for a separate action

Shell Scripting - part 3

Fun with Shell scripting
-------------------------
----


tput cup command
-----------------
This command is used to set properties of terminal

tput cup 0 0
This command will set courser position to top left corner of terminal

e.g:-
[root@localhost]#vi file6.sh
tput cup 0 0
echo "Ansil"


Save and execute script
The output "Ansil" will be displayed on top left corner of the terminal

e.g:-
Lets make this example more interesting

#!/bin/bash
clear
tput cup 12 35
echo "Ansil"
read

Save the file and execute the script
The out put will display "Ansil" on almost center of the screen,
Surprisingly you will not get your terminal back until you press enter OR you have to kill/terminate the script(we will discuss this later)

The read command is used to read values from terminal(by default standard input)

here the read command read values till an occurrence of ENTER key ,but the value will not be stored

e.g:-
Make this example some more interesting

#!/bin/bash
clear
tput cup 12 35
echo -e "\033[31mAnsil\033[0m"
read

The echo line having some extra characters ..!!

More on echo command
---------------------------
echo -e --->what is -e
:- enable interpretation of backslash escapes
echo -e "\033[31m ------>what is \033[31m
:-Start printing charecter from here in red
:-\033[ is a backslash escape character
:- in 31 3-forground 1-for red
echo -e"\033[31mAnsil" ----->It will print Ansil in red color ,Then why

echo -e "\033[31mAnsil\033[0m"
:-The \033[0m will make the terminal to normal state
:- i,e from \033[0m the characters will be printed normally
:- If you did't typed this on your script ,after execution also the character printed will be in red

Colors and attributes using echo
---------------------------------
Foreground
-----------
\033[30m - BLACK
\033[31m - RED
\033[32m - GREEN
\033[33m - YELLOW
\033[34m - BLUE
\033[35m - MAGENTA
\033[36m - CYAN
\033[37m - WHITE

background
-----------
\033[41m - BLACK
\033[41m - RED
\033[42m - GREEN
\033[43m - YELLOW
\033[44m - BLUE
\033[45m - MAGENTA
\033[46m - CYAN
\033[47m - WHITE
More
------------
\033[4m - UNDERLINE
\033[24m - STOP UNDERLINE
\033[5m - BLINK
\033[7m - INVERT FORGROUND AND BACKGROUNG
\033[1m - BOLD

e.g:-
print Ansil in bold with color green and background red in bottom right corner of terminal

#!/bin/bash
clear
tput cup 23 00
echo -e "\033[41m\033[32m\033[1mAnsil\033[0m"

we will split the echo line
echo -e ---->You know this
\033[41m --->Make background red
\033[32m --->Make foreground green
\033[1m ---->Make foreground bold
Ansil -------->The word to be printed
\033[0m ---->Make default printing colors

Thursday, April 14, 2011

Shell Scripting - part 2

Command Line Arguments
-------------------------------
Here we will discuss some more about command line arguments( values passed along with script like flags in commands)
and how they can be accessed in script

1)Name of the program
The name of the program is stored in variable '0'
So the value can be accessed as ${0}
e.g:- vi file1.sh
---------------------------------------------------------------------
#!/bin/bash
echo ${0}
---------------------------------------------------------------------
The output of the program will be like
./file.sh
2)All arguments passed along with script
All values passed to the script(command line arguments) will be stored in variable '@'
So the value can be accessed as ${@}
e.g:- vi file2.sh
---------------------------------------------------------------------
#!/bin/bash
echo ${0}
---------------------------------------------------------------------
If you execute the script with out any arguments,there will be no output
So to verify the script ,execute with some arguments like

root@localhost]#./file2.sh a b c

The output of the program will be like
a b c
3) Number of command line arguments
Number of arguments passed to the program will be stored in variable '#'
So the value can be accessed as ${#}
e.g:- vi file3.sh
---------------------------------------------------------------------
#!/bin/bash
echo ${#}
---------------------------------------------------------------------
If you execute the script with out any arguments,there will be no output
So to verify the script ,execute with some arguments like

root@localhost]#./file2.sh a b c

The output of the program will be like
3
4) PID of shell executing the script
variable that will store PID of shell executing will be on $ or _
So the value can be accessed as ${$} or ${_}
The PID of shell executing will depend on how you execute the program

The script can be executed in two way
a) on current shell
e.g:-
root@localhost]#. file3.sh
5388
b) on a separate shell
root@localhost]#./file3.sh
5344

On e.g (a) the PID displayed will be the PID of current shell
You can verify it using 'ps' command
root@localhost]#ps
PID TTY TIME CMD
5388 pts/0 00:00:00 bash
5464 pts/0 00:00:00 ps
5) Command line arguments
So finally we are on the actual arguments
The values that are passed to the script for processing

The values start with 1

e.g:- vi file4.sh
---------------------------------------------------------------------
#!/bin/bash
echo ${1}
echo ${2}
echo ${3}
---------------------------------------------------------------------
Execute the program with some arguments

root@localhost]#./file4.sh a b c
a b c

Thats for Now we will continue with more on coming posts

Tuesday, April 12, 2011

Shell Scripting - part 1

The echo command
------------------
The easiest command in shell script
used for display text

e.g:-
echo "Hello world"

Variables in script
--------------------
variables are used for storing values
It may be pe-defined or the value will be assigned on the fly (On execution of script)

The variable manipulation in scripting
VAR=value

${VAR} for retrieving the value assigned to VAR


a)Pre-defined
e.g:-
VAR=10

b)On the fly
e.g:-
VAR=`expr ${i} + 1`

In example (a) the variabe VAR is assigned a value of 10
The value of VAR will be 10 through out the execution life of script(unless that variable is not alterd by another assignment)

In example (b)the variable VAR assigned a value that depend on the value of 'i' (another variable)
We will split the example to understand two command

expr ${i} + 1
and
VAR=


i) evaluat the expression ${i} + 1
ii) Assign the result to VAR

Using the echo command we can display the value assigned to a variable

e.g:- Write a script that having a variable VAR and assign a value 10 to it
Display the value of VAR in terminal
---------------------------------------------------------------------

#!/bin/bash

#
# Dispaly the value of a variable

VAR=10
echo ${VAR}

---------------------------------------------------------------------

Monday, April 11, 2011

Basic Shell Scripting-step by step

Basic Shell Scripting-step by step

If you are not a beginner go to summery page

What is a script?

Group of commands in one file for a specific or a number of actions to achieve a result

Shell script structure

1. Select your editor

You must have a text editor to write shell programs

Select an editor in which you are comfortable

Most common editors are Vi and Emacs

2. Structure of a script

a)First line

“#!/path/to/shell”

b) Comments

Purpose of script, author, created date, modifications, bug fix notes etc

c) Body of script

Commands to be executed

This line will decide which shell to be used for executing the commands in script

If the line is not present, system will use default shell

E.g.:- 1

------------------------------------

#!/bin/bash

echo “Hello world”

E.g. Explained

------------------------------------

The above script will execute

echo “Hello world”

in bash shell

3. Execute a script

If you logged in as root, the home directory will be /root/

We will create a file in /root using vi editor

[root@localhost]# vi hello.sh

The files have an extension of “.sh” so that others can easily identify the file as script

-------------------------------------------------------------------------------------------------------------------------------

Note: - The “file” is a command used to identify, what kind of file it is.

Suppose we have file with name “abcd” How can I say it is a shell script or an executable binary or else another type..?

Here we will use “file” command

Eg:-

[root@localhost]# file abcd

ASCII Long line text

-------------------------------------------------------------------------------------------------------------------------------

We are in vi now (I’m going ahead with the assumption that you have basic knowledge of VI editor)

Type the text mentioned in e.g.: 1

#!/bin/bash

echo “Hello world”

Save the file

Now we have created a” bash shell script” named as “file.sh”

To execute a file that need execute permission

So give execute permission to “file.sh” using chmod command

[root@localhost]# chmod 755 file.sh


Now we can execute the script as

[root@localhost#]./file.sh

Hello world

[root@localhost#]

Summary

1. Create a script that will print “Hello world”

[root@localhost#]

[root@localhost#]

[root@localhost#]vi file.sh

#!/bin/bash

echo “Hello world”

[root@localhost#]chmod 755 file.sh

[root@localhost#]./file.sh

Hello world

[root@localhost#]

LVM thin provisioning - file system usage and pool usage dosn't match

When I was demonstrating LVM thin provisioning to new batch of campus hires ; they pointed out an important mismatch between thin pool usag...