Programming
How to open a popup window upon page load
Feb 28th
In JavaScript, window.open method can be used to open link in a new window. This method can be used to open a new window when a page is opened. However this method of opening a pop-up window will be blocked by recent browsers as part of their pop-up advertisement blocking feature.
Place the following code in your HTML file.
<script type="text/javascript"><!--
window.open('http://techpulp.com');
//--></script>
Auto SSH login using ‘expect’ tool
Feb 28th
The “expect” tool can be used to achieve auto login for interactive commands like telnet, ftp, ssh and others. Automatic login is useful to avoid unnecessary delays in work and also useful in automation. However this method requires your password to be stored in the script in plain text. But you can set the file permissions so that you only can access it.
Using “expect” tool, we can spawn a command and expect certain messages from server and send user-defined strings to automate interactive prompts. So the script will be typically specific to a server because other server may prompt for More >
Bash script to replace a word or a string in multiple files at once
Feb 21st
There are multiple ways of replacing a word or a string with another in a stream of input. Here, in this article, we use “sed” command. While the “sed” command operates on one file at a time, the bash script takes care of iterating it through multiple files and making backups of original files. Run the following script with no arguments to view help.
#!/bin/bash
usage() {
echo Usage: $0 str-from str-to files
echo e.g: $0 "this string" "that ring" file1.txt file2.txt file3.txt
exit 1
}
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" More > How to set up a CVS server in Linux
Feb 18th
Repository Initialization
First create a directory to be used as CVS repository and initialize it as shown below.
[root@techpulp ~]# mkdir /cvsroot [root@techpulp ~]# chmod 1777 /cvsroot
Initialize the repository for the first time
[root@techpulp ~]# cvs -d /cvsroot initInstall inetd or xinetd
The CVS server requires either legacy “inetd” or latest “xinetd” package be installed in the system. If you don’t know how to find it, look for the presence of “/etc/inetd.conf” file for “inetd” package and look for the presence of “/etc/xinetd.d” directory for “xinetd” package. If none of them is present, you should install “xinetd” package. You can install a More >
Concurrent Version System (CVS) Quick Guide
Feb 18th
CVS is a heavily used source control system both in open source projects and commercial projects. This article explains frequently used commands by a developer.
Set the command-line environmentFirstly, before using cvs command, the CVSROOT environment variable should be set to point to CVS server. This command can be placed in ~/.bashrc to make it as default environment.
[neo@techpulp ~]# export CVSROOT=:pserver:neo@cvs.techpulp.com:/cvsroot
In the above command, cvs.techpulp.com is the CVS server, neo is the user name on the CVS server and /cvsroot is the base of the CVS repository in the server.
It is not necessary that CVS must be used only with remote CVS server. If you More >
Bash script to delete blank lines from a file
Feb 14th
There are multiple ways of deleting blank lines from a file. This article tells how to use “grep” command to achieve the objective. The “grep” command provides an option “-v” to invert the matching. That means grep finds the lines that are not matching the pattern specified. The matching pattern is a simple regular expression to match all blank lines i.e “^$“. The “^” character means beginning of a line and “$” means end of a line. The pattern matches all blank lines as there are no characters between “^” and “$” characters.
Here is the sample file “sample.txt” that contains More >
How to take password interactively in a Bash shell script
Feb 14th
If you are not familiar with interactive bash programming, please read this article as well. Typically “read” command is used to prompt the user to respond and read the input from standard input. The “read” command, by default, shows whatever is typed by the user on the terminal. But for reading a password on terminal requires character echo to be turned off. The “read” command provides an option “-s” to read the input in silent mode. Please note that “read” is an in-built command provided by Bash shell.
The following example script shows how to implement it.
#!/bin/bash PASS="cool" read -s -p "Password: More >
How to set time out to interactive prompt in Bash
Feb 13th
If you are not familiar with how to show interactive prompt in Bash shell script, please read this article first. Typically “read” command is used to read the response from the user. By default, the “read” command waits forever for the user input. However the “read” command supports an option “-t” which makes it to wait specified number of seconds for the user input. If user hasn’t provided the complete input, the “read” command exits with non-zero value. Looks at the following example to understand the behaviour of “read” command.
[neo@techpulp ~]# read -p "u like bash (y/n)? " -t 1 u More >


Recent Comments