Thursday, December 15, 2011

One line Python Web server

if you have python installed, go to your terminal. Go to the directory you want to serve HTML files from, then type one of the following, depending on your python version:

Python 2.x:

python -m SimpleHTTPServer


Python 3.x:

python -m http.server 8000

Monday, December 12, 2011

Get Notifications from Your Scripts with notify-send

Notify-send is a great application for notifying you when an event has occurred. An event such as a script running to completion.

If notify-send is not installed on your machine already, install the package "libnotify1" (or possibly just "libnotify") from your repositories.

Once installed you can simply type the following, at the command line, to display a pop-up message near your system tray:

notify-send "hello"
By default the message will be displayed for 5 seconds. To change how long a message stays displayed use the "-t" switch. This will change, in milliseconds, how long the message is displayed. Enter "-t 0" to leave the message up until the user closes it.


notify-send "This message will be displayed for 3 seconds" -t 3000
notify-send "Click me to close me." -t 0


You can even add a title and an icon to the notification.

notify-send "This is the Title" \
"Check out the cool icon" \
-i /usr/share/pixmaps/gnome-terminal.png

When used in a script you could set it to notify you periodically by placing the command in a loop:

#!/bin/bash

while [ 1 ]; do
notify-send "Up Time" "`uptime`"
sleep 5m
done

Disabling Bash History Temporary

Say that you’ve got to pass some password as command line argument to something. It would probably be a bad idea to store it in your ~/.bash_history, but clearing the file isn't desired either. So you need to temporary disable the command history for the current session. You can do it by unsetting the HISTFILE environment variable.

unset HISTFILE


The result is that while the session is active you can access the history as usual, but it won't be saved to the disk. History for other sessions, will behave as usual.