Linux goodies …contd…..

Check UR system state

vmstat -memory information
dmesg -booting information
top -process management and mem information
nmap – number of ports open
netstat -network statistic


How to configure a linux box to act as a ROUTER

There are two ways of doing the same :

1. echo 1 >> /proc/sys/net/ipv4/ip_forward
Though the effect of this command cannot survive a reboot & a re-run of the above command or specifying the same in any of the startup script will be enough to keep your linux box forwarding packets.

2. You can edit /etc/sysctl.conf & change the value of net.ipv4.ip_forward = 1 . But you got to restart your box to bring it in effect.


Consolidate your radio streams with streamtuner

Streamtuner is a point-and-click GUI browser for the thousands of Internet radio streams available today. It lets you play streams and manage your favorites in a single window — like a Linux tuner for Internet radio.

Streamtuner has a GTK 2.0 interface and is published under the revised BSD license. It lets you use plugins to browse and search popular portals including SHOUTcast and Icecast.

You don’t need streamtuner to listen to Internet radio stations, of course — the usual method is to go to a station’s stream page, or its entry in a portal like SHOUTcast, and click on the stream link to start an audio player. But streamtuner gives you a way to consolidate all of your favorite streams, find new ones, and play and record them in one place. It’s essentially an X Window front end that pulls together all the existing pieces; the play and record mechanisms are farmed out to other applications (XMMS and Streamripper are the respective defaults).


Cut and paste text files by columns

Here’s a generic UNIX way: (startcol and endcol refer to character columns, including whitespace. Tab counts as 1.)
cut -cstartcol-endcol file {>receiving file} paste sourcefile1 sourcefile2 {>final file}



In the .login file add the commands:

echo login time `date` >> .daylogs/masterlog

grep -i “sun” .daylogs/masterlog > .daylogs/sunday.log
grep -i “mon” .daylogs/masterlog > .daylogs/monday.log
grep -i “tue” .daylogs/masterlog > .daylogs/tuesday.log
grep -i “wen” .daylogs/masterlog > .daylogs/wensday.log
grep -i “thu” .daylogs/masterlog > .daylogs/thursday.log
grep -i “fri” .daylogs/masterlog > .daylogs/friday.log
grep -i “sat” .daylogs/masterlog > .daylogs/saturday.log

In the .logout file add this line

echo logout time `date`>> .daylogs/masterlog

This script assumes you have a hidden
directory called .daylogs this helps keep it
out of sight and away from prying eyes and
if you keep root ownership of the directory
change the mode to:

chmod 744 .daylogs

This will not allow anyone to get in to the
directory to look around.


Multiple X-Sessions….

Using multiple X-Sessions allows a user to have open more than just one instance of XFree, so multiple desktop environments can be used at a time.

startx — :

terminal name is simply which terminal X should start on. By default it starts on

0:0. If you want two open, you may want it open on 0:1, which can be run by:

startx — :1

The resulting desktops will exist on F7 – F12.


gzexe command

gzexe command
gzexe [option] [files]

Compress executables. When run, these files automatically uncompress, thus trading time for space. gzexe creates backup files with a tilde at the end (filename~). These backup files can be deleted once you are sure the compression has worked properly.

-d Decompress files.


“You can edit /etc/sysctl.conf & change the value of net.ipv4.ip_forward = 1 . But you got to restart your box to bring it in effect.”

u can use #sysctl -p without restart the system, it will load the current setting from …../sysctl.conf file.

#lsof -p <pid> :to see the list of open files by that process.


Finding Who Has a File Open

How often do mounts and umounts fail because you can’t determine what is using the device? How many times can you not eject a CD because something’s got it open? How many times have you experienced a “file browser” that keeps a directory open even after you’ve navigated out of that directory and clicked the “refresh” button? Who’s got this thing open??? Use thefuserprogram to find out:

[piyush@ test]$ /sbin/fuser -mu /d
/d: 1693(piyush) 1891c(piyush) 1894 1894c(piyush)
1907 1907c(piyush) 1908 1908c(piyush) 1909 1909c(piyush)
1910 1910c(piyush) 1912 1912c(piyush) 1913 1913c(piyush)
[piyush@ test]$

You get the owner and the process ID. From there you can research using ps ax.

Be sure to look at the fuser man page for details on other info you can obtain. You can even kill all processes accessing a file, though I highly recommend against such a heavy handed move.

Linux goodies … contd .. oss..

Temporary Increase of SWAP size through a file.

1. dd if=/dev/zero of=/tmp/MyTempSwapFile bs=1024 count=65536
“Define Size of the file 1024*64=65536 i.e. 64MB of file
2. mkswap /tmp/MyTempSwapFile “Create File
3. swapon /tmp/MyTempSwapFile “Swap On
4. /tmp/MyTempSwapFile swap swap defaults 0 0 “Fstab entry
5. Check in /proc/swaps


Autonegotiation off

ethtool -s eth0 speed 100 duplex full autoneg off

The above command will set the network card to 100Mbps Full Duplex with Autonegotiation off



LVM can be implemented on RAID, here is how u can do it.

Login as root and create 2 partitions with 1500MB (or any value u like, provided u have the required free space) using fdisk. Set the partitions type to ‘fd’, save and exit from fdisk. Run “partprobe” (without quotes!), this instructs kernel to recognise the newly created partitions or reboot linux.

Assuming the new partitions created are /dev/sda7 and /dev/sda8, run these commands:
mkfs -t ext3 /dev/sda7 (creates ext3 filesystem on the partition)
mkfs -t ext3 /dev/sda8

To Create a RAID device with any of these 2 commands
mdadm –create /dev/md0 -level=1 –raid-devices=2 /dev/sda7 /dev/sda8
(creates a raid device, md0. md=multiple device)
mdadm -C /dev/md0 -l 0 -n 2 /dev/sda7 /dev/sda8

mdadm –query /dev/md0 or #mdadm -Q /dev/md0
mdadm –detail /dev/md0 or #mdadm -D /dev/md0
cat /proc/mdstat

Moving on to LVM,
pvcreate /dev/md0 (creates a physical volume)
vgcreate redhat /dev/md0

(creates a volume group by the name “redhat”)
vgscan (optional)
vgdisplay (optional)
lvcreate -L +800M -n linux /dev/redhat
(creates a logical volume of size 800MB)
lvscan (optional)
lvdiplay (optional)
mkdir /mnt/lvm
mount /dev/redhat/linux /mnt/lvm


wget & proxy authentication

wget is a fine tool for automated downloads. but since it lacks interactive nature, it accepts passwords as clear text arguments. to rectify this, use following simple c program which acts as an interface for wget:
// code < save it as wgetcurses.c>
int main(int argc,char *argv[]) {
char pass[10];
char command[100];

printf(“Enter the proxy authentication password:”);
sprintf(command,”wget –proxy-user=csu02138 –proxy-passwd=%s %s”,pass,argv[1]); //replace csu02138 with something appropriate !
return 0;
//end of code

compile it with the following command ..
cc -lncurses -o nwget wgetcurses.c

now, your normal wget command ( for eg wget ) will just become nwget
after typing the above command you will be prompted for authentication password, supply the same and off u go !

similar scripts can be written for other commandline programs like lynx etc.

shell script compiler—(shc)

Shc is a generic shell script compiler. It takes a script which is specified on the command line and produces C source code. The generated source code is then compiled and linked to produce a stripped binary executable.


Simple folder/file sharing can be done like this:

Simple share a folder/file between Unix machines:-
There are two ways to do that:
1)create a folder under /tmp and assign 755 permissions to that folder so everyone can read the contents but can’t modify.
Create a group, add desired members, assign 775 permissions so that only group members have read write permissions and others read and execute.
Lot of permutation combinations are possible to do that, but best way is to create that folder on locations such as:-

For sharing between Unix & MS Windows use SAMBA Share.


Selenium —– a test tool for web applications

Selenium is a test tool for web applications. Selenium tests run directly in a browser, just as real users do. And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh. No other test tool covers such a wide array of platforms.
* Browser compatibility testing. Test your application to see if it works correctly on different browsers and operating systems. The same script can run on any Selenium platform.
* System functional testing. Create regression tests to verify application functionality and user acceptance.


Managing Bash command history

The Bash shell is the default shell environment in most Linux distributions, including all flavours of Red Hat. One default feature of the Bash shell is to record a history of all the commands entered by a user in a log file called .bash_history, found in the user’s home directory.The history in this file can be retrieved from the command line using the more or cat binaries or by using the internal Bash command, history. For many users, it is useful to retrieve the previously executed commands, usually to save the effort of re-typing them.So why might we want to limit or disable this Bash command history? Well, among the commands that your users type are file names, command names, IP addresses, passwords and a myriad of other data that are potentially valuable to an attacker intent on subverting or compromising your host. Keeping a record of this data means an attacker may only need to compromise an individual .bash_history file rather than a more difficult source of data.To limit the size and behaviour of the .bash_history file, you need to edit the behavior of the shell in the /etc/profile file (the central version of the .bash_profile file usually contained in users home directories). Add or change the following three lines to the file:
export HISTSIZE=100
The first two lines set the length and size of the history stored in the file. The last line unsets the HISTFILE variable that tells the Bash shell not to save history when the user logs out of the interactive session. This means an online user will only be able to see the history of the last 100 commands, and that history will disappear after the user logs out of the host.
A further way to ensure the command history is removed is to include a command in the .bash_logout file (other shells use the .logout file). The contents of the .bash_logout file are executed when the user logs out. You can see a simple .bash_logout file on the following lines:
# ~/.bash_logout
/bin/rm -f $HOME/.bash_history

Some Linux goodies…. < /dev/null :)

uptime – Prints the system uptime.
w – Prints the current system users.
wall – Prints a message to each user except those who’ve disabled message reception. Type Ctrl-D to end the message.
no root!
If /etc/securetty is world writeable then root will not be able to log in.
Permission of /etc/securetty is 600
If you change this to 606, root can not log in.
how to make ur floppy bootable…???
fdformat /dev/fd0
mkfs /dev/fd0
mount /dev/fd0
cp ks.cfg /media/floppy

in the prompt type (without quotes) “linux ks=floppy”
wants to automount the samba shares
Edit the /etc/auto.master file

vi /etc/auto.master

# $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa Exp $
# Sample auto.master file
# Format of this file:
# mountpoint map options
# For details of the format look at autofs(8).
/misc /etc/auto.misc –timeout=60

Then save this file

Now edit the /etc/auto.misc file
vi /etc/auto.misc

# $Id: auto.misc,v 1.2 1997/10/06 21:52:04 hpa Exp $
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

samba -fstype=smbfs,username=[username],passwo

rd=[password] ://server/share

# the following entries are samples to pique your imagination
#linux -ro,soft,intr
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0

Then restart the autofs service