Archive for February, 2009
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 identify empty files or directories in Linux or UNIX
Feb 14th
The “find” command supports an option “-empty” to find files with zero size and directories which have no files and sub-directories.
The following command finds empty directories:
[neo@techpulp ~]# find . -empty -type d ./Documents/External ./Music/jazz ./Templates ./TestDir [neo@techpulp ~]#
The following command finds files with zero size:
[neo@techpulp ~]# find . -empty -type f ./Documents/draft1.doc ./Documents/testone.txt ./Music/download/u-and-me.mp3 [neo@techpulp ~]#
Similarly you can get the list of empty files and directories together with the following example:
[neo@techpulp ~]# find . -empty ./Documents/External ./Documents/draft1.doc ./Documents/testone.txt ./Music/download/u-and-me.mp3 ./Music/jazz ./Templates ./TestDir [neo@techpulp ~]#
If you want to clean up all empty files and directories recursively, you can use “xargs” command as shown below.
[neo@techpulp 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 >
How to show interactive YES/NO prompt in Bash
Feb 12th
The Bash shell provides an in-built command “read” to read a line from the standard input. The following sample script prompts user to provide his answer as either “yes” or “no“.
[neo@techpulp ~]# cat yesno.sh #!/bin/bash echo -n "Do you like blue color (yes/no)? " read color if [ "$color" == "yes" ]; then echo "YES: That's great. I like blue color too." else echo "NO: Never mind." fi [neo@techpulp ~]#
In the above script “echo -n” is used to print the prompt message to keep the cursor in the same line. Here is what happens when the script is run and More >
How to align a HTML element like DIV or table in Center using CSS
Feb 4th
To center align a DIV or a table, use “margin” property in CSS. Look at the example HTML file below.
<html>
</head>
<title>DIV center align demo</title>
<style>
.calign { margin: 0 auto; }
div { width: 60%; background-color: #fff; }
body { background-color: #333;}
</style>
</head>
<body>
<div class="calign">This is my DIV aligned in center</div>
</body>
</html>
In the avobe example HTML file, “margin: 0 auto;” makes the DIV element to align in center.
How to resolve “POST to /wp-admin/post.php not supported” error in WordPress
Feb 1st
Sometimes while posting in WordPress blog software, users encounter the following error and fail to submit the new post or edited post.
Method Not Implemented POST to /wp-admin/post.php not supported. Apache/2.2.0 (XenOS) Server at techpulp.com Port 80
This error is due to mod_security which is enabled on your Apache server. The mod_security helps protect your website and is called Open Source Web Application Firewall. It comes with a big set of rules against which each server request is matched to detect any hacker trying to compromise your website. In a way mod_security is very good to have it enabled as a security measure. but More >


Recent Comments