How to run scripts in Linux faster than Cron does

Cron is an amazing job scheduler. But, when it comes to running your scripts in less than every minute, it can’t help.

With Cron, you can run your scripts every minute, but not in shorter period of time.

This problem can be solved with simple bash script. For example, if you need to run a PHP script on every 20 seconds, you can create a bash script like this:

#!/bin/bash
#Name:myscript.sh
#Desc:Run script in every 20 seconds
while (sleep 20 && php /path_to_your_script/your_script_name.php) &
do
 wait $!
done

Then, make script executable, and add it to the system startup. That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter

Grabbing HTTP headers with Python [ 7 lines of code ]

As I mentioned in one of my previous post, I started with learning Python.

Here is one of the first scripts I wrote. It grabs the HTTP Response header. Great thing is that it’s possible to do this with only 7 lines of code.

Script code:

#!/usr/bin/python
import urllib2
import sys
url = raw_input("Full url:")
url.rstrip()
header = urllib2.urlopen(url).info()
print(str(header))

Example usage:

$>python headers.py
$>Full url: http://www.jovicailic.org



As a result, you should get something like:

Date: Wed, 13 Mar 2013 12:35:43 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimi
ted/1.4
X-Powered-By: PHP/5.2.9
Vary: Accept-Encoding,Cookie
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

If you liked the post, we should get connected - follow me on Twitter