Archive for the ‘bash’ Category

Automatically Restart Your Python SimpleHTTPServer

02232011

Command Line Fu turned me on to python’s built-in servers a while ago, unfortunately, root tends to kill my long-running processes. Schedule the below in cron to tickle the default python webserver port and start a new instance of the python webserver in the specified <ROOT_DIR> if no response.


(echo '' > /dev/tcp/localhost/8000) 2>/dev/null || (cd /<ROOT_DIR> && /bin/python -m SimpleHTTPServer &)

If this doesn’t work, your BASH was compiled without network support. wget should be able to help you.