Thursday, September 29, 2022

Using cron to schedule GUI programs

I needed to schedule a GUI program . I chose cron to do it however cron is not meant to schedule GUI programs . Cron does not know anything about user environments so u'd need to pass vars to it. For example the $DISPLAY env  var   


To edit/create a local crontab

crontab -e 

Here I am running a GUI program at 12:15 AM and terminating it at 5:50 AM ( there are better ways to terminate though ;) )

15 00 * * * DISPLAY=:0 /usr/bin/somegui

50 05 * * *  /usr/bin/pkill somegui

Sunday, September 18, 2022

Trivial line for Splitting file names

 

I have a Bluetooth speaker with USB support. Come next storm ( and power disruption) I have one pen drive full of classic rock songs . The problem is they are named as such " Artist - Song.mp3  and in the dir, they play alphabetically .. ah darn .. all AC/DC songs at one go.. lets change the file names as such "song.mp3" :-)

 

 for i in *.mp3 ; do  mv -v "$i" "${i#* -}"  ; done


does the trick . Bash pattern matching 

Thursday, October 29, 2020

Trivial "tea timer" :-)

 

I've gotten fond of tea these days .. especially  "Twinnigs earl grey" .. I prefer it seeped for 2.5 minutes .. so I wrote a trivial tea timer to time my teas . The default is 3 minutes . It's convenient as the image chosen gets displayed over screen even if mplayer is playing a movie in full screen. 

                                            I'm using Feh which is a fine image viewer. .. cheers.

 

 t=180
if [ $1 ] ; then  t=$(echo "$1*60" | bc ) ; fi
t=$(echo $t | awk -F "." '{print $1}')
i=0
echo "$i"
while [ $i -lt $t  ] ; do let  i=$i+1 ; echo $i ; sleep 1; clear;   done
echo " $i seconds"  
feh -F ~/tea.jpg



Sunday, March 22, 2020

DIY hand sanitizer

Hand sanitizers have become the talk of the day as the world fights the covid-19 pandemic. Its is possible to make your own , here's how :

Ingredients :

1) isopropanol (rubbing alcohol)  atleast 70% v/v
2) Aloe vera gel
3) fragrance (optional)
4) spray bottle or dispencer



Method :

take a clean vessel and mix 1 part aloe vera gel to 3 parts isopropanol . add few drops of fragrance and mix well. Fill the spray bottle . done.

note: gel is used for ease of spreading (over hands) and as a moisturizer since alcohol dries the skin.

Be safe and stay at home. These bugs are dangerous

Friday, July 6, 2018

USB 3.0 on Linux ( AMD processors )

You'll find at times that your USB 3 device is running on USB 2 speeds. This  can be addressed by passing a  kernel parameter in grub. "amd_iommu=on" 

The input–output memory management unit (IOMMU) is a memory management unit (MMU) that connects a direct-memory-access–capable (DMA-capable) I/O bus to the main memory.

To make the changes permanent, add the parameter to /etc/default/grub 

GRUB_CMDLINE_LINUX_DEFAULT="amd_iommu=on"

and run "sudo update-grub"


Remember that  the effective transfer rate will be dependent on internal disks and other possible bottlenecks . 

Saturday, June 30, 2018

TP-Link TL-WN725N wireless USB adapter on Linux

The default driver which is auto loaded by the kernel does not seem to work as expected . The workaround is simple. Go to the TP link site here : 

https://www.tp-link.com/us/download/TL-N725N.html#Driver

download the driver , unzip the file and ,

$ apt-get install gcc

$ make clean
$ make


then


$sudo cp 88x2bu.ko /lib/modules/[kernel version]/kernel/drivers/net/wireless/ #[kernel
version] is the directory name of the system kernel version

$ sudo depmod  –a
$ sudo modprobe 88x2bu.ko

in my case it was 8188eu.ko

lsmod to check

Blacklist the existing module by adding  the line

blacklist   r8188eu

to  /etc/modprobe.d/blacklist.conf 

unplug the dongle and plug it back again .

Seems to work perfectly now! :) 



Monday, February 2, 2015

Flash plugin vulnerability warning in firefox 35.0.1


There seems to be some incompatibility between ubuntu and flash releases . I never liked flash player because it tuns very inefficiently on linux  but anyways if you have the vulnerability warning ,

do this :


1 ) Get the tar bundle from   http://get.adobe.com/flashplayer/
2 ) tar -xvzf   install_flash_player_11_linux.i386.tar.gz
3 ) sudo cp libflashplayer.so  /usr/lib/mozilla/plugins/
4 ) Restart firefox


Its trivial and  irritating .. but this solves the problem..



Thursday, October 2, 2014

pulse audio clicking/popping sounds

After a recent routine update , my audio streams had clicks /pops in it which did not seem to occur  synchronously  . After some investigation I figured out that the problem was with pulseaudio  timer based scheduling . This parameter is driver specific and may be required "on" on some sound cards. 


To turn timer-based scheduling off add tsched=0 in /etc/pulse/default.pa
After editing the above file , restart pulse audio  sudo service pulseaudio restart
  
This fixed my clicks and pops but introduced another glitch which i'm working on right now. Alsamixer is reset every time I play mplayer .. aaarrgh !!!

UPDATE :  That fix was irritating . Pulse is probably broken since the latest update  . The best thing to do is use JACK :) . jack can coexist with pulse and is lighter , more efficient and works great .

start it by using  " jackd -d alsa -r 44100 "   and to make mplayer use jack , just use vo=jack :)

Problem solved

Saturday, June 28, 2014

Multiple displays with xrandr

Do you have a LCD TV or a spare monitor ? You can use that extra screen size  to see more code  : ) or watch a movie.  It's easy to manage multiple displays in linux using xrandr. Install xrandr if you havent already . I use a trivial script to switch between my displays . Here it is :


 #!/bin/bash
# switch from VGA to LVDS ( xrandr )
#####################################

# set wall to the path of your wallpaper
frm=$1
wall="/full/path/wallpaper.jpg"

if [[ $frm -eq 1 ]]
then
        xrandr --output VGA1 --auto
        sleep 2
        xrandr --output LVDS1 --off
        fbsetbg $wall  
else
        xrandr --output VGA1 --off
        sleep 1
        xrandr --output LVDS1 --auto
        fbsetbg $wall
fi



use xrandr --query  to check which displays have been detected and change the names of the displays accordingly. Also , If you are using fluxbox then make sure that  it's compiled with xinerama support. It helps with the window geometries etc. when switching.  Use a keybinding in fluxbox to switch from  VGA (tv) and LVDS ( laptop) so that if there is a power cut , you wont have a switched off laptop screen ! .

Monday, March 24, 2014

Fixing the "Whiteout" for the samsung 21 inch TV

Samsung has a design flaw in their LCD TV's . The  flaw leads to something called a "whiteout" wherein the screen turns bright white and  nothing is displayed. The problem is a PCB situated on the top back of the panel . This PCB is covered by a metal cover with which it eventually shorts. Insulating The metal studs under the metal cover solves this issue! . Use insulating tape (electrical tape ) . Also Insulate under the PCB . Just in case .. Don't stick tape to PCB! .. just under PCB and over the metal studs touching the PCB .

JKturner has an excellent article on the same so I wont repeat the whole thing here . His  however is for the 32 '' TV. It's a good read for anyone attempting to solve the 21 inch but remember , on the 21, there is only one PCB at the top back of the panel (after you have removed the chassis housing the motherboard and SMPS).

An open TV chassis can be somewhat intimidating to some, so be brave but be gentle with the internal  connectors. BTW,  this became my first TV hack partly because I was too lazy to take it to the service center :P and partly because It appears that the service center folks misdiagnose it ( perhaps deliberately !) as a blown panel and charge the consumer for a new one ....  and the whole hack worked like a charm !! .

happy hacking

Monday, September 30, 2013

My Timex Ironman leaked!!

Had a nice dip in the Arabian sea and when I was  walking back to the shore I glanced at my trusty Ironman timex .. The screen was blank !!!. I couldn't  believe it . Back home I opened the back cover and discovered that the o-ring was slightly misaligned . I took one strap off , took the machine out of its casing , cleaned the inner casing , placed the machine back , aligned the o-ring , screwed the back cover on to the casing and attached the strap to the casing . 

You will need a precision kit ( small screwdrivers) to service this watch.

  • 1) take one strap off : carefully press the pin release with a screwdriver and slide the pin out of the groove. Gently pull the strap in one direction .
  • 2) Unscrew the metal cover
  • 3) Align the o-ring in it's groove and keep it aligned while closing the back cover
  • 4) close the back cover and tighten  alternate (opposite) screws . 
  • 5) make sure all screws are tightened properly
The battery can be easily replaced by unhooking the battery cover gently from its plastic hooks using a pin . The case once opened needs to be very carefully reassembled to avoid losing the water resist. Silicone sealant is recommended but I didn't have any  so I sealed it just by cleaning the rubber o-ring . 

    Wednesday, September 4, 2013

    Speeding up vmplayer over x11 ssh tunneling with compression

    Are you running vmplayer (or any other remote gui) over ssh ?  Chances are it's going to be slow unless you've enabled compression and chosen a faster cypher. this is how you can :

      ssh -X -C -c blowfish  remoteuser@remotehost_or_ip


    Performance is significantly improved :)

    Friday, August 30, 2013

    Making a bootable pen drive in one command

     Well you can make one in a single command and it works like a charm.  Here's how :

    1) plug in your pen drive
    2) Run dmesg and check the drive letter (identifier) ( eg /dev/sdb)
    3) Run the following command :


    dd if=ubuntu.iso  of=/dev/sdb  bs=4M ; sync 


    Note : if is your iso file .  DONOT append any trailing number to the pen drive

    Thats it ...

    Tuesday, August 20, 2013

    VMware player 5.0.2 on linux ( ubuntu 12.04 LTS ) and mint 17 - Installation

    Updated june 2017 . The following has been tested on mint 17 as well

    Virtualisation is very useful if you want to experiment with network stacks , web servers , load balancers etc. Open source offerings like Xen are out there but the industry standard seems to be vmware. The following is about  how one can go about installing it on linux .

    Observations:
    1) The vmware site is a very typical "corporaty"  mess . not easy to use.
    2) All thet you get via google is a vmware download page with rpm's.
    3) Don't download from third party sources , the binary could be tainted!

    Distro : Ubuntu 12.04 LTS   (  LTS 's are usually more stable )

    Install the dependencies :

    $ sudo apt-get install build-essential linux-headers-$(uname -r)


    Get the "bundle" :

     wget -c http://goo.gl/JXy7L -O VMware-Player-5.0.2-1031769.x86_64.bundle.tar

    note : The shortened URL points to a vmware hosted download server

    The above link no longer works !!!!
    WORKING LINK : ( June 19 2017) :
     wget -c https://www.vmware.com/go/tryplayerpro-linux-64

     $chmod +x tryplayerpro-linux-64

    Create a directory say VMware and move the bundle to that dir. The just run the "bundle".

    ./tryplayerpro-linux-64


    Have fun :)



    Friday, May 24, 2013

    Grilled keyboard with fries and mayo

    It is very important to keep that base of your notebooks ventilated. Plonk it on a soft pillow and play flash games for long hours and what you get is grilll.. That's exactly what a girl who plays a lot of flash games did .. :P  . 

    The thing to remember is that even though some processors like the intel atom are capable of operating at 100 deg C !  the other things may not be . In this case the thin keyboard somehow got all the heat and fried !! . 

    you can keep a watch on the core temperature using something like this :

     cat /proc/acpi/thermal_zone/TZ00/temperature

    Also its good practice to us a frequency governor  and keep the processor on "power save"    unless you  really need the extra cycles.

    Wednesday, April 24, 2013

    fork bombz

    The first time I saw this series of characters (was about ~= 10 years ago)  .. They looked interesting and not very harmful. So I ran the code .. and a few seconds later my system froze.  Try this (in bash) :

                                              :(){ :|:& };:

    Its basically a function recursively calling itself  .. The way to protect the system against this us to set ulimit -u ( number of user processes)  to some finite value ..Its fun to play with them though .. 

    warning : you may have to hard reboot your system .. ( no biggie for people accustomed to windoze )

                                  

                                 

    Tuesday, April 16, 2013

    Firestarter log parser scriptlet

    Some time ago, I  noticed constant incoming traffic on one of my boxes . Firestarter was running on it and I thought I'd give the "events log" a look . There were like 1000+ blocked connections many of which looked like scans .. and many were .. The most scanned port was ms-sql ( not surprised at all ) . So I whipped up a quick scriptlet to get the top 20 IP's and "whois" them  to know where they were coming from .. 

    The results :

    ---------------- 124 scans from 91.198.174.234 ------------------------
    descr:          Wikimedia's Amsterdam cluster (knams)
    descr:          Wikimedia Foundation, Inc.
    country:        NL
    address:        Wikimedia Foundation, Inc.
    address:        USA
    address:        US
    address:        San Francisco, CA 94105 USA
    address:        San Francisco
    address:        CA 94105 San Francisco
    address:        CA 94105
    address:        3rd Floor
    address:        3rd floor
    address:        149 New Montgomery Street
    address:        149 New Montgomery, 3rd Floor
    ---------------------------------------------------------------
    ---------------- 109 scans from 91.198.174.233 ------------------------
    descr:          Wikimedia's Amsterdam cluster (knams)
    descr:          Wikimedia Foundation, Inc.
    country:        NL
    address:        Wikimedia Foundation, Inc.
    address:        USA
    address:        US
    address:        San Francisco, CA 94105 USA
    address:        San Francisco
    address:        CA 94105 San Francisco
    address:        CA 94105
    address:        3rd Floor
    address:        3rd floor
    address:        149 New Montgomery Street
    address:        149 New Montgomery, 3rd Floor
    ------------------------------------- 37 scans from 81.0.237.38 ------------------------
    descr:          Gransy s.r.o.
    descr:          Casablanca INT
    country:        CZ
    address:        Vinohradska 184, Prague 3 - 130 52
    address:        Czech republic
    address:        Casablanca INT
    ---------------------------------------------------------------
    ---------------- 18 scans from 58.221.60.159 ------------------------
    descr:          China Telecom
    descr:          CHINANET jiangsu province network
    descr:          Beijing 100088
    descr:          A12,Xin-Jie-Kou-Wai Street
    country:        CN
    address:        No.31 ,jingrong street,beijing
    address:        260 Zhongyang Road,Nanjing 210037
    address:        100032
    ------------------------------------------

    ---------------- 10 scans from 42.96.185.184 ------------------------
    descr:          Chaoyang District,Beijing
    descr:          Alibaba (Beijing) Technology Co., Ltd.
    descr:          9F,Tower A Winterless center,NO.1 West Da Wang Lu,
    country:        CN
    Comment:        using this IP address range and is not able to investigate
    Comment:        This IP address range is not registered in the ARIN database.
    Comment:        spam or abuse reports relating to these addresses. For more
    address:        No.99 HuaXing Rd. Hangzhou,310099
    ---------------------------------------------------------------
    ---------------- 8 scans from 87.93.45.81 ------------------------
    descr:          DNA Oy
    descr:          DNA Finland
    country:        FI
    address:        PL 41
    address:        Finland
    address:        DNA Oy
    address:        01741 Vantaa
    ---------------------------------------------------------------


    Sciptlet :
    ------------------------------------------------------------------------
     #!/bin/bash

    # scriptlet to know where the scans are coming from

    echo "Enter the firestarter events file"
    read $events

    tmp="event_tmp"
    tmp_who="tmp_who"


    egrep -o -h   "Source:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"   $events  \
     | awk -F ":" '{ print $2 }' | sort | uniq -c | sort -nr | head -10  > $tmp


    while read line
    do
            count=`echo $line | awk '{ print $1 }'`
            ip=`echo $line | awk '{ print $2 }'`
            whois $ip > $tmp_who
            echo "---------------- $count scans from $ip ------------------------" 
                  cat $tmp_who | grep  'country\|address\|descr' | sort -r | uniq
            echo "---------------------------------------------------------------"
            sleep 1
    done < $tmp

    rm $tmp $tmp_who

     -------------------------------------------------------------------------

    Conclusions :

    • Miscro$oft products are most searched by worms n scanners
    • Firestarter is a hack . n ot for professional use
    • A lot of folks/worms from china scan everyone else all the freakin time!!

    :)  

    Sunday, March 31, 2013

    Raydio saved my life tonight ...

    I just wanted a nice radio player with which i can play , save and rip my fav stations ( from shoutcast.com) . I searched .. could not find any .. I found a plugin from rhydmbox but the thing was sending traffic to unknown shady hosts .. so I junked it .. and started writing my own little script . 

    Its called raydio :) its nice .. command line and easy ..

    :-)