Blogs

Dancing LED

How can I make bash my login shell?

Every time, I do SSH to my Linux box, the default shell comes as: csh, but I want to, use the bash shell automatically from PuTTY. For making bash as the default login shell, first we need to find out, the path of the bash shell, by using:

which bash

If your login shell is csh or tcsh, and you have installed bash in /bin/bash then create a ~/.login file and add the following line:

Passwordless SSH Using Key Based Authentication with Putty

SSH (Secure Shell) is a protocol for connecting two computers securely. It provides secure authentication as well as encryption. If you use Linux, most distros have ssh installed by default.

You can log to a Linux machine using SSH protocol from a putty client by entering the username and password. But if, both the machines are yours only, and no one else uses those machines, it makes a hindrance to enter the username and password, every time you do SSH to that server.

How to read/write from a file, like you are reading from the stdin/stdout?

Using the freopen function you can read/write from a file, like you are reading from the standard input/output. freeopen first tries to close any file already associated with the stream given as third parameter and disassociates it.

Move cursor by display lines when wrapping in vi

You can move your cursor by display lines when wrapping in vi, instead of jumping to the next line. This can be really helpful, when you have long wrapped lines, and you want to move in between them.

Just edit the .vimrc file.

vi ~/.vimrc

and insert the following text into that:

nnoremap <up> gk
nnoremap <down> gj
inoremap <up> <C-o>gk
inoremap <down> <C-o>gj

Show line numbers in vi or vim

Displaying line numbers while editing a file can be handy. Using line numbers you can directly jump to a particular line. You can set the line numbers in vi using the following commands:

:set number

If you want to turn off the line numbers in vi, use the following command:

:set nonumber

You can also insert the following text into the .vimrc file, and can switch on or off the line numbers, by pressing the F6 and F7 keys respectively.

Using FTP Batch Scripts on Windows

The Microsoft KB article 96269 shows you how to use the ftp program that comes with all versions of windows to automate file transfer. You can use the -s option for passing FTP script to the program.

File Checksum Integrity Verifier utility

Many times we face situations where a bug is not reproducible on a particular version in our environment, but the customer or supports says, that its reproducible at their ends, but they can't share that environment due to security concerns.

Shell script to download file using ftp

#!/bin/sh

# ftpget - given an ftp: style URL, unwrap it, and try to obtain the file using ftp.

if [ $# -ne 2 ] && [ $# -ne 3 ]; then
  echo "Usage: $0 ftp://... username [password]" >&2
  exit 1
fi

# Typical URL: ftp://ftp.ncftp.com/2.7.1/ncftpd-2.7.1.tar.gz

if [ "$(echo $1 | cut -c1-6)" != "ftp://" ] ; then
  echo "$0: Malformed url.

Arrowhead Antipattern

Another common Anti-pattern is the Arrowhead Antipattern. Refactoring away from the arrowhead antipattern is as simple as swapping the conditionals, i.e. flatten conditionals statements, to leave the method as soon as possible. It is so common and so much have been written about it, I thought to just copy the links: