BMX Bicycle freestyle
BMX Bicycle freestyle

Sunday, June 14, 2009

power off from terminal

script is not perfect and may need your customization. It was written so you can end programs and power off your system from terminal

requrements:xvkbd ~6mb
code (add programs running on your system):

(ps ax | grep -v grep | grep transmission) #check if transmission is running if [ "$?" -eq 0 ]; then b=$(xwininfo -name Transmission | grep Window\ id:\ | awk '{print $4}') #get programs window id xvkbd -xsendevent -window $b -text "\Cq" #send keystroke to quit program fi sleep 1 #set firefox title to normal firefox about:blank sleep 1 (ps ax | grep -v grep | grep gnumeric) if [ "$?" -eq 0 ]; then b=$(xwininfo -name Book1.gnumeric\ :\ Gnumeric | grep Window\ id:\ | awk '{print $4}') xvkbd -xsendevent -window $b -text "\Cq" fi (ps ax | grep -v grep | grep nicotine) if [ "$?" -eq 0 ]; then b=$(xwininfo -name Nicotine+\ 1.2.9 | grep Window\ id:\ | awk '{print $4}') xvkbd -xsendevent -window $b -text "\Cq" fi sleep 1 (ps ax | grep -v grep | grep firefox) if [ "$?" -eq 0 ]; then echo firefox running, now trying to end #(using different character c) c=$(xwininfo -name Mozilla\ Firefox | grep Window\ id:\ | awk '{print $4}') xvkbd -xsendevent -window $c -text "\Cw"; sleep 1 xvkbd -xsendevent -window $c -text "\Cq"; fi df xvkbd -xsendevent -window $c -text "\Av"; (ps ax | grep -v grep | grep linuxdcpp) if [ "$?" -eq 0 ]; then b=$(xwininfo -name LinuxDC++ | grep Window\ id:\ | awk '{print $4}') xvkbd -xsendevent -window $b -text "\Cq" fi (ps ax | grep -v grep | grep vlc) if [ "$?" -eq 0 ]; then b=$(xwininfo -name VLC\ media\ player | grep Window\ id:\ | awk '{print $4}') xvkbd -xsendevent -window $b -text "\Cq" fi #send once again commands to firefox in case it wasnt running xvkbd -xsendevent -window $c -text "\Cw"; xvkbd -xsendevent -window $c -text "\Cq"; (ps ax | grep -v grep | grep transmission) if [ "$?" -eq 1 ]; then echo transmission now off, poweroff? #last resort to end firefox killall firefox sudo shutdown -P now fi

article will be updated as donation recieved

Wednesday, June 10, 2009

Low disk space notifications

linux low disk space notifications

Pre-requisite

In order for the pop-up message to appear, you would need to install “libnotify-bin”.

Code:
sudo apt-get install libnotify-bin


Script

The script will check the free disk space in “/dev/sda1″. It will show a pop-up message for 30 seconds when the free space is below 100MB. If the free space is below 50MB, it will show a pop-up message for 5 minutes. You should modify these parameters to your own requirement.

Copy and paste the script below to a file called “checklowdisk”.

Code:
#!/bin/sh

DISKSPACE=`df | grep "/dev/sda1" | awk '{ print $4 }'`

if [ "$DISKSPACE" -lt "51200" ] ; then
/usr/bin/notify-send -u critical -t 300000 \
'Check low disk' '/dev/sda1 is less than 50MB.'
exit
fi

if [ "$DISKSPACE" -lt "102400" ] ; then
/usr/bin/notify-send -u normal -t 30000 \
'Check low disk' '/dev/sda1 is less than 100MB.'
fi



Setting up the script

Make the script executable:

Code:
chmod +x checklowdisk


Change file ownership to root:

Code:
sudo chown root:root checklowdisk


Move file to “/usr/bin”:

Code:
sudo mv checklowdisk /usr/bin/


Set-up crontab

I chose to run the script hourly using crontab.

Edit crontab:

Code:
crontab -e


Add this line in the editor:

Code:
00 * * * * env DISPLAY=:0 /usr/bin/checklowdisk


Save and close the editor. The crontab is now configured, and the script will run at the hour.
thanx:Chewearn

to free up disk space more effectively click here