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

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...