Neo
This user hasn't shared any biographical information
Posts by Neo
How to write infinite loop in Bash using for or while statement
Oct 17th
The while-do-done statement can be used to program an infinite loop in bash. The following sample shows how it can be done.
#!/bin/bash while [ 1 ]; do echo I am in infinite loop. Press Ctrl+C to stop me done
The break statement can be used to exit the while loop. The following sample code breaks away from while loop after iterating 10 times.
#!/bin/bash
i=1
while [ 1 ];
do
i=`expr $i + 1`
echo loop $i
if [ "$i" == "10" ]; then
echo Exiting while loop after iterating $i times
break
fi
done
echo end of shell script
The following will be the output More >
How to generate temporary file name in bash using RANDOM environment variable
Oct 17th
Whenever the $RANDOM environment variable is accessed, it gives a random number. This can be used to generate a random file name. In the following example randfile function takes prefix and suffix of the temporary file name and returns a temporary file name after checking for its existence.
#!/bin/bash
function randfile
{
while [ 1 ];
do
TNAME="$1""$RANDOM""$2"
if [ ! -f $TNAME ]; then
echo $TNAME
exit 0
fi
done
}
NAME=`randfile /tmp/test- .tmp`
echo $NAME
How to scan all reserved ports on a host using nmap
Oct 9th
nmap is a very useful network exploration tool and security scanner. It can be used to scan all open ports on a host. The following example shows how it can be used. However port scanning is just one of the many features of nmap.
[neo@techpulp ~]# nmap 127.0.0.1 Starting Nmap 4.20 ( http://insecure.org ) at 2008-10-09 12:28 IST Interesting ports on localhost.localdomain (127.0.0.1): Not shown: 1692 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 631/tcp open ipp 904/tcp open unknown 8000/tcp open http-alt Nmap finished: 1 IP address (1 host up) scanned in 0.292 seconds [neo@techpulp ~]#
More >
View page source with a link or a button using Java Script
Oct 9th
window.location can be set to a special location using view-source: followed by window.location.href to make browser to display source code of the current page. This can be attached to a standard link or a click of a button as shown below.
The following shows how to fire view-source window using a standard link: Place this code between <head> and </head> tags of the page.
<script language=JavaScript>
function viewSource() {
window.location = "view-source:" + window.location.href;
}
</script>
Place this code where you would like your link to appear.
<a href="javascript:viewSource()">View Source</a>
Alternately if button needs to fire the view-source window of the browser, add the following piece of code More >
How to prompt for e-mail on click of a button using Java Script
Oct 9th
In general a standard link can be created to prompt for an e-mail as shown below and it doesn’t involve Java Script.
<a href="mailto:neo@techpulp.com">Mail to Neo</a>
However same functionality can be attached to a button using onClick event of the button as show below. But this requires Java Script support.
<form>
<input type="button" value="Email Neo"
onClick="location.href='mailto:neo@techpulp.com'">
</form>
Moving to previous page in browser using Java Script
Oct 9th
history.go method in Java Script can be used to make the browser go back to previous page in history. This can be invoked using a normal link or on click of a button. The following examples show how to do that.
Go to last page if a link is clicked:
<a href="javascript: history.go(-1)">Back</a>
Go to last page if a button is clicked:
<input type="button" value="Back to Previous Page"
onClick="javascript: history.go(-1)">
How to redirect a page in Java Script
Oct 9th
window.location can set to URL of a page to which redirection is desired. This can be done by placing the Java Script code between head tags. The following example show how a page redirects to http://techpulp.com/newpage.php upon loading. The redirection URL can be changed to any URL.
<head> ... <script language="JavaScript"> window.location="http://techpulp.com/newpage.php"; </script> ... </head>
Reload/Refesh a window in Java Script
Oct 9th
The method window.location.reload() can be used to reload the current browser window in Java Script. This can be invoked on various events like click of a normal link, click of a button etc. The following examples show how to do that.
Reload current window if a link is clicked:
<a href="javascript: window.location.reload()">Reload Window</a>
Reload current window if a button is clicked:
<form method="post"> <input type="button" value="Reload Window" onclick="window.location.reload()"> </form>
How to close a window with a link using JavaScript
Oct 9th
The method self.close can be used to close the current browser window in Java Script. This can be invoked on various events like click of a normal link, click of a button etc. The following examples show how to do that.
Close current window if a link is clicked:
<a href="javascript: self.close()">Close Window</a>
Close current window if a button is clicked:
<form method="post"> <input type="button" value="Close Window" onclick="window.close()"> </form>


Recent Comments