Automatically Restart Your Python SimpleHTTPServer

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.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.