Skip to main content

Posts

Script to bind to slow routers by persistent requests to release DHCP information

This script is to persistently nag the router to release DHCP information. The script must be run as root. This is for slow routers or one which is overloaded with clients. Do not use for normal routers. Otherwise it could be misconstrued as a security threat. persistent bind connection DHCP script ------------------------- # script to persistently nag the router to release DHCP information : must be run as root # persistent bind connection DHCP script b=`expr 1` while [ $b -lt 2 ] do echo "Starting new DHCPREQUEST .... after 5 secs ... " sleep 5 /etc/init.d/networking restart echo -e "\n xxxxxxxxxxxxxxxxxxxx \n `tail -n 20 /var/log/syslog` \n xxxxxxxxxxxxxxxxxxxx \n" if [ "` tail -n 20 /var/log/syslog | grep "DHCPOFFER" | grep "of 192"`" ] ; then echo -e "\nExiting inf. loop .............\n" b=`expr 3` fi done

Fastest way to send multiple drafts from gmail

People claim that the fastest way to send multiple email drafts is to use Gmail IMAP with email client like Outlook or Evolution or Thunderbird. But I have found this is not true. Because Thunderbird and Evolution etc. email clients treats the drafts as emails still to be edited. So it is not just simple select all and hit send. Each email draft has to be opened and sent separately. That is a lot of clicks and mouse movements, wasting precious time and energy. I have a better solution which involves minimum keystrokes and mouse usage. Efficiency booster technique for sending emails. If someone is feeling adventurous and want to try it from the Gmail interface itself, here's how to do it in the fastest possible manner. It involves using the mouse once. Select the first draft. Gmail would open a new email box and put the cursor inside the box to write. Press TAB once to go the Send button. Press ENTER to send. Now Gmail sends it and the box is gone but the highlight goes to the last...

How to play movies in PS3

PS3 supports a wide variety of video formats. But there are multiple caveats regarding the playback all relating to the licensing of propriety codecs. PS3 plays avi, mp4 etc. but only some codecs like xvid are playable. mkv files will not play. If it a direct presonal copy from a DVD VOB file it can play. Also, it refuses to play some formats from external media. In that case copying to the PS3 local disk might work. PS3 is not supposed to play single video files due to DRM(Digital Rights Management). However, if some personal video like a party video is concerned and someone want to play in on a bigger TV screen rather than a PC then it is understandable. If it is laptop it might have a HDMI output so no need to go through alll the hassle. but if there are no laptops then it makes sense to use the PS3 to view videos. To view videos in PS3 it is best to encode all videos with the xvid codec. This is easily acheived with mencoder. mencoder -idx inputfile.dat -ovc xvid -oac mp3lame -la...

A simple laptop battery monitor script

The script displays alert when the battery falls below 20% or charges up beyond 80% which should be the optimal range of its working.The code is as below. Just copy and paste and save as any file name but preferably battery-notify.sh. The script can independent of what name it is given. Needs to have acpi (default install) and notify-send installed (sudo apt-get install notify-osd). ============================================ #!/bin/bash # battery-notify v2.5.1 by JOnes # It is a script to monitor battery and keep it between 20% to 80% the optimal battery working range. If the battery goe beyonds the set limit it gives pop-ups every 10 seconds. No sound warning as sound can easily be muted and ignored. # Things that could be added : 1> The flexibilty of range. But it is not recommended hence not implemented. 2> Notification in form of email or sms. 3> Sound / beep for critical state of battery. # The script goes into background. To kill it at any time use : battery-notify.sh...

Self terminating code for bash scripts

Self terminating code for bash scripts is very easy. But have to be sure not to kill itself in the process. The procedure is simple. Find all the PID with the same name as itsself $0 and then kill all those instances one by one in a for loop except itself $$ (PID of its own). This is a very general script and could be used anywhere and in any script. =================================== if [ "$1" != "" ] ; then # if no command line parameter supplied then move on. if [ "$1" == "kill" ] ; then # if command line parameter is "kill" then kill all running instances of this script. nnn=`ps aux | grep $0 | tr -s " " | cut -d" " -f2 ` echo -e $$ "\n====" # prints PID of this instance of script. make sure not to kill itself. for ii in `echo $nnn` do if [ "$ii" -ne "$$" ] ; then echo "Killing PID:" $ii kill -9 $ii fi done exit fi fi

Random wallpaper change script for Linux

This script would change wallpaper at regular intervals in a random manner. The script can also be killed at any time from any terminal. just like pulseaudio. #For eg. my-laptop>$ ./wallpaper-changer.sh kill Usage: wallpaper-change.sh [option] [option] = kill : Kill all running instances of the script = change : Change the wallpaper = dir : Change the wallpaper directory to = -h : Display this help. =============================================== #!/bin/bash # Wallpaper randomizer script # written by JOnes v4.1.5 # this script keeps rotating the wallpapers at a fixed interval and does it randomly. # It goes into background. You can either kill it manually or use the "kill" switch as a command line parameter. # location of wallpapers / pics. wallpaperdir="$HOME/Pictures" # wallpaper change interval time in seconds. Cannot changed during runtime. changetime=1800 # do not have to edit be...

find if another instance of the same script is running in background

A bash script snippet to find if another instance of the same script is running in background. This code snippet is very useful for those scripts which have to stay in the background and do some scheduled tasks or just plain monitoring like the laptop battery. It is supposed to be included at the beginning of the code. It would check if another instance of the script is running as a background job. If yes then it issues a warning and terminates the script. A note of warning : For multicore CPUs it is a tricky deal to figure the actual number of instances. If CPU is dualcore then echo ${run_count} outputs 2 for the first run. And for the second time around it outputs 3. The extra number is the suspended instance of the script. For quadcore the number would go as 4 -> 5 -> 6. For for the first time just run without the comment on echo ${run_count} and then set the value of exp_count (2 for dualcore , 4 for quadcore etc.). ================================================ process=...

Dopamine induced learning

While watching the killer whales and dolphins perform at the San Diego waterworld, I wondered what motivates these animals to display such acquired skills. I understand that it is the food that they get which prompts such abnormal behavior. But where did the process of learning triggered in those primitive brains. I believe it is the Dopaminergic neurons that are responsible for the learning behavior. These neurons have a predictive error response, which means they give a good stimulus to the brain in a reward comes along. But if expected rewards are not obtained it causes depression. This is known as motivation to us. If we get good results in a job we get motivated to do it. If not we get depressed. So, logically we always do something which gives maximum reward, that is, we always try do something we are good at. Wikipedia article -- " In nature, we learn to repeat behaviors that lead to maximizing rewards. " This is true even for animals. They repeat the behavior which re...
Nowadays normally Ubuntu mounts external hard drives without the executable bit set as a precaution against dangerous scripts from running automatically. Without the executable bit set it becomes impossible to run scripts from external hard drives. However, setting the executable bit is not as hard but little bit laborious. So I wrote a small script to decrease the load. In order to set the executable bit for the normal user the specific partition has to be unmounted as root and then remounted by the normal user with SSID and setting the executable bit so that he has execution permission. The normal remounting process could be done in the userspace so it is all included in the script but the unmounting requires root privilege. Since, sudden unmount can freeze open files and cause data loss if the mount point is removed forcibly (rm -rf) I have not included it in the script. So the unmounting has to be manually by the user with root privileges. So if using a public computer or a shared...

Gateway Netbook LT2802u tinkering

This Gateway Netbook LT2802u is a very compact machine. You need to take it apart in order to even install RAM. So I opened it up for fun and put it back. In order to open the Gateway netbook there are many guides. First read the instructions on http://dl.dropbox.com/u/26855544/Gateway%20LT28%20Series%20Netbook%20Repair.pdf from (  http://gadgetgeekgrrl.blogspot.com/2011/08/netbook-memory-upgrade.html ) then see the following video http://www.youtube.com/watch?v=uBM9jbhUpkc and then see the tips at http://www.notebookforums.com/t/237671/lt2802u-ram-xp-install-instructions The last link gives crucial tips on how not to scratch your laptop. So use a thin laminated card or a Safeway card (not your credit card) instead of a screwdriver. If you are still using a thin flat screwdriver then cover its tip with some thin paper like a receipt. But do not try to remove those thin T-shaped screws which hold the keyboard in place and visible from the battery compartment...