Saturday, September 13, 2008

Vim under cursor word search


To search for a word under the cursor in the current file you
can use either the "*" or "#" keys.

The "*" key will search for the word from the current cursor
position to the end of the file. The "#" key will search for the
word from the current cursor position to the top of the file.

Thursday, July 3, 2008

Using WGET to download files through http_proxy

setup the env then execute the wget command as below:

export http_proxy=http://www-proxy.company.com:80


wget --output-document=jdk-1_5_0_15-linux-i586.bin http://cds.sun.com/is-bin/jdk-1_5_0_15-linux-i586.bin

Sunday, June 8, 2008

To find all listening ports and their programs

netstat --tcp --udp --listening --program

The output is something like the below:

# netstat --tcp --udp --listening --program
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:exec *:* LISTEN 4284/xinetd
tcp 0 0 *:nfs *:* LISTEN -
tcp 0 0 *:login *:* LISTEN 4284/xinetd
tcp 0 0 *:53730 *:* LISTEN 15445/oidldapd
tcp 0 0 *:shell *:* LISTEN 4284/xinetd
tcp 0 0 *:1830 *:* LISTEN 10930/emagent
tcp
0
0
*:33033
*:*
LISTEN
23649/java

Friday, April 11, 2008

perl bad interpreter: No such file or directory..windows EOL characters

This problem happens when editing scripts on a windows based system then FTP'ing them to unix/linux boxes.
This simple Perl command always seems to clear up the problem. Try the following command on your text file then try and run it.

perl -i -pe's/\r$//;'

Tuesday, March 25, 2008

Restoring Windows MBR with ubuntu LiveCD

Boot into your Ubuntu LiveCD on the offending machine. Once Ubuntu starts up,
go to System -> Administration -> Software Sources and enable (by checking it off) the Universal repository.

Now, open a terminal session (Applications -> Accessories -> Terminal) and type the following:

sudo apt-get install ms-sys

ms-sys(http://ms-sys.sourceforge.net/) is a program used to write Microsoft compatible boot records.

Now you’ll need to figure out what partition is the one hosting your Windows operating system. Back in the command line, type:

sudo fdisk -l

That will list the available partitions. You’re looking for a partition that says something like

/dev/sda1 1 9327 74919096 83 NTFS

The two important bits are the ‘/dev/sda1‘ which is the partition itself and the ‘NTFS‘ which tells us it’s a Windows formatted partition. So your Windows partition exists on your drive sda and it’s partition 1. The MBR for drive sda (assuming you boot into windows using it’s native boot loader) is what you want to repair.

We want to fix the MBR on /dev/sda. To do so, type:

sudo ms-sys -m /dev/sda

You’ll want to change the ’sda’ bit if your results from ‘fdisk -l‘ are different. If for instance your windows install is on sdb or hda.

Once you do that, reboot the machine, removing the LiveCD from the drive and Windows should come back to you.

Sure, you could do this by inserting the correct Windows CD and booting into repair mode from it - but I find the Ubuntu way a bit faster and I’m more likely to have an Ubuntu LiveCD on me than a Windows CD.

Thursday, February 21, 2008

Useful software to get your dynamic ipaddress on Windows 2000 reboots


Download the sendEmail.exe from http://caspian.dotconf.net/menu/Software/SendEmail/
and put it in some directory and make sure you update the setup.bat file accordingly to reflect the proper directory paths as can be seen below:




Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>cd C:\Devel\sendemail

C:\Devel\sendemail>dir
Volume in drive C has no label.
Volume Serial Number is 7472-D5BA

Directory of C:\Devel\sendemail

02/20/2008 03:12p .
02/20/2008 03:12p ..
12/21/2006 07:14a 1,531,966 sendEmail.exe
02/20/2008 03:16p 241 sendip.bat
02/21/2008 05:54p 294 ipmsg

C:\Devel\sendemail>type sendip.bat
ipconfig > "C:\Devel\sendemail\ipmsg"
"C:\Devel\sendemail\sendEmail.exe" -f sendmail@kns.com -t yourEmailID@yourcompany.com -u "New ip address" -s rgmapacsmtp.kns.com -o tls=auto -o message-file="C:\Devel\sendemail\ipmsg"

C:\Devel\sendemail>




Now go to your Start --> Settings --> Control Panel --> Scheduled Tasks --> Add Scheduled Task and create a new task in the next window, Browse for location of sendip.bat -> Select "When my Computer Starts" -> Enter your password .

You need to edit the c:\sendmail\sendip.bat and instead of yourEmailID@yourcompany.com put your company's Email-ID .
and instead of rgmapacsmtp.kns.com you need to give you company's smtp server.

Great now you will get your dynamic ip emailed to you when you require to connect to your machine in future.

Remote Desktop or Netmeeting for Windows 2000 Prof. sucks big time

Better to go with tightVNC and tlntadmn on Windows 2000 Prof.


This is how you do it:
Download the TightVNC server and unzip the package to a directory say C:\tgtvnc

now run the below:


C:\tgtvnc> WinVNC -install --> which will install the service.
C:\tgtvnc>net start winvnc --> which will start the service.


Also open up the Start -> settings -> Control Panel --> Administrative Tools --> Services window and make sure "VNC Server" the "Startup Type" is Automatic so on reboot you winvnc starts up also.

Now for you back just in case winvnc fails on you and you need to start it up again.
For this we have the tlntadmn command to start you telnet server on Windows 2000.

As below:


C:\>tlntadmn


Microsoft (R) Windows 2000 (TM) (Build 2195)
Telnet Server Admin (Build 5.00.99201.1)

Select one of the following options:


0) Quit this application
1) List the current users
2) Terminate a user session ...
3) Display / change registry settings ...
4) Start the service
5) Stop the service

Type an option number [0 - 5] to select that option: 3


Select one of the following options:

0) Exit this menu
1) AllowTrustedDomain
2) AltKeyMapping
3) DefaultDomain
4) DefaultShell
5) LoginScript
6) MaxFailedLogins
7) NTLM
8) TelnetPort
Type an option number [0 - 8] to select that option: 7
Current value of NTLM = 0
Do you want to change this value ? [y/n]y
NTLM [ current value = 0; acceptable values 0, 1 or 2 ] :0
Are you sure you want to set NTLM to : 0 ? [y/n]y

setting will take effect only when Telnet Service is re-started


Select one of the following options:

0) Exit this menu
1) AllowTrustedDomain
2) AltKeyMapping
3) DefaultDomain
4) DefaultShell
5) LoginScript
6) MaxFailedLogins
7) NTLM
8) TelnetPort
Type an option number [0 - 8] to select that option: 0

Select one of the following options:


0) Quit this application
1) List the current users
2) Terminate a user session ...
3) Display / change registry settings ...
4) Start the service
5) Stop the service

Type an option number [0 - 5] to select that option: 4
Starting Microsoft Telnet Service ...
Microsoft Telnet Service started successfully

Select one of the following options:


0) Quit this application
1) List the current users
2) Terminate a user session ...
3) Display / change registry settings ...
4) Start the service
5) Stop the service

Type an option number [0 - 5] to select that option: 0

C:\>

Now again to make sure your telnet server comes up on reboot as above in the
Services window change for "Telnet" the "Startup Type" to Automatic.

That's it now you can telnet to you Windows 2000 box using:


bash-3.00$ telnet 10.177.247.50
Trying 10.177.247.50...
Connected to dhcp-v412-10-177-247-52.kns.com (10.177.247.50).
Escape character is '^]'.
Microsoft (R) Windows (TM) Version 5.00 (Build 2195)
Welcome to Microsoft Telnet Service
Telnet Server Build 5.00.99206.1
login: srikanth
password: ********

*===============================================================
Welcome to Microsoft Telnet Server.
*===============================================================
C:\>net stop winvnc
The VNC Server service is stopping..
The VNC Server service was stopped successfully.


C:\>net start winvnc
The VNC Server service is starting.
The VNC Server service was started successfully.


C:\>exit

Note sometime you might have to use Shift-Backspace for the Backspace to work for you.

How to delete Windows 2000 services entries

Download the delsrv.exe for windows and run delsrv serive_name.

Remind you just deleting the entry in registry is not the proper way to do it.

Tuesday, February 19, 2008

Instead of Reinstalling Windows 2000 and your applications on blue screen or other crashes

To recover from a corrupted filesystem/files on your windows C: filesystem
you can do the below:

Make partitions of FAT32 30GB each for C: D: etc,
After you have installed all the required software make a linux ext3 filesystem
to tar up your C: dirs/files and you can untar them back whenever required.

Here is the process below:
boot up with puppylinux3.01 and do
cfdisk /dev/hda --> here hda could be some other like hdc or hdb
select new partition on the /dev/hda1 or whatever you have no filesystem on.
the select type and change the type to Linux(83) filesystem
finally write the filesystem to disk, becarefull at this point and don't mess up your windows partitions.
then finally format it to a ext3 filesystem which is usable with mkfs as below:
mkfs -t ext3 /dev/hda3 --> again hda3 can be hda5 or whatever your used in cfdisk

Now your ready to tar up your c: directories and files as below:
You will have Drives Icon on the puppy desktop select it.
you will see that you /dev/hda3 got created. Now you need mount both of these
files systems i.e. is the /dev/hda1 with your windows c: in it and your newly created
linux ext3 filesystem.
Just click on the icons with disk drive images on them to mount both drives.
You can observe the got mounted on your /mnt/hda1 and /mnt/hda3 locations:
Now open up your Console Terminal
cd /mnt/hda1 --> that is your windows location.
tar -cf /mnt/hda3/win2kcdrv.tar *

That's it.
So next time say your drive got screwed up just boot up with puppy linux, mount
your drives delete your "Program Files" "WINNT" or any other files you think might have got corrupted and recover you windows system.

You can use the procedure below to extract and copy files back to your c:
lets as above your c: is on /mnt/hda1
cd /mnt/hda1
mkdir recover; cd recover
tar -xf /mnt/hda3/win2kcdrv.tar

No you will find all your driectories in /mnt/hda3/recover where you can manually copy the required files or directories :).

Saturday, January 26, 2008

Using awk, gawk to print multiple matching lines in multiple files

This basically prints the trio of source, destination and include only
when include either contains libnmt.a or libnml.a

egrep -e 'source|destination|include' *.map.xml | awk '/source/ {SRC=$0}; /destination/ { DEST=$0}; /libnmt\.a/ || /libnml\.a/ { print SRC "\n" DEST "\n" $0}'

How type @ symbol when mapped to stty EOL


Some Times you cannot use the @ symbol or other keys on the keyboard
In order to type them you can first type Ctrl-v then your symbot or keyboard key.


eg.
Ctrl-v @

Thursday, January 17, 2008

xterm color and font settings




examples:
xterm -sl 3000 -fg black -bg grey -bd orange -cr darkgreen -fn 9x15

xterm -sl 3000 -fg black -bg grey -bd orange -cr darkgreen -fn 10x24

for showing scrollbar:
xterm -fg black -bg grey -bd orange -cr darkgreen -fn 9x15 -sb -si -sl 3000


to view the fonts available use
$xlsfonts