Sunday, April 03, 2011

Turn your laptop to alarm clock

I bumped into an article describing rtcwake here, so I thought it will be cool to write a nice wrapper script around it.
It was also an excuse to master some more bash scripting and the use of "date" command.

There are many many other implementations for rtcwake script, like here for example, and I've seen some other cases in the Ubuntu forums, after I finished writing mine. So with out further a do, here is my solution, which is easy to use:

#!/bin/bash

#       GoodMorning.sh
#       
#       Copyright 2011 Oz Nahum <nahumoz_ATTNOSP_gmail.com>
#       
#       This program is free software; you can redistribute it 
#       and/or modify it under the terms of the GNU General 
#       Public License as published by the Free Software 
#       Foundation; either version 3 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will 
#       be useful, but WITHOUT ANY WARRANTY; without even the
#       implied warranty of MERCHANTABILITY or FITNESS FOR A
#       PARTICULAR PURPOSE.  See the GNU General Public 
#       License for more details.
#       

if [ $5 ] && [ $5 !=  "test" ]; then
    PLAYLIST=$5
    PLAYER=$4
else
    PLAYLIST=$4
fi

if [ $PLAYER ] && [ $PLAYER = "mplayer" ] ; then
   PLAYER="mplayer -playlist"
else
   PLAYER=$4
fi


#echo "player is" $PLAYER
case "$1" in

    "")
        echo "  usage: GoodMorning.sh --help to see this how to use that script"
        exit 1
        ;;
    
    "--help")
        echo "  GoodMorning.sh [--set|--configure]   "
        echo " "
        echo "  Options:"
        echo "  --set"
        echo "  --configure"
        echo ""
        echo "  GoodMorning.sh --set   [player|playlist]"
        echo "      will set the correct time for the script to wake the computer "
        echo "       with a lovely playlist."
        echo " "
        echo "  GoodMorning.sh --configure "
        echo "      will add the specified  to the sudoers list, so that rtcwake" 
        echo "      can be called without promting for password. This option is not yet"
        echo "      implemented. This option is only available with sudo or as root..."
        ;;  

    "--set")
        IN=$3
        arrIn=(${IN//:/ })
        
        echo "will set up wake up to ${arrIn[0]}:${arrIn[1]} $2"
        TODAY=`date +%F`
        TODAY_IN_SEC=`date --date=$TODAY +%s`
        TIME=`date -d "$2 00:00:00" +%s`
        
        WAKE_UP_TIME=$(($TIME+3600*${arrIn[0]}+60*${arrIn[1]}))
        
        echo "date to wake up" `date --date "1970-01-01 $WAKE_UP_TIME sec" "+%Y-%m-%d %T"`
        # check if testing mode
        if [ "$5" = "test" ] || [ "$6" = "test" ]; then

            echo "testing only", $PLAYER, $PLAYLIST
            sudo rtcwake -t $WAKE_UP_TIME -m on -v && $PLAYER $PLAYLIST         
        else
            sudo rtcwake -t $WAKE_UP_TIME -m mem -v && $PLAYER $PLAYLIST        
        fi
        ;;
    "--configure")

        if  [[ $EUID -ne 0 ]]; then
            echo "This script must be run as root" 1>&2
            exit 1
        fi
        
        echo "Will add user " $2 "to sudoers file so that,"
        echo "$2 will be able to call it without password"
      
        echo "$2 ALL= NOPASSWD: /usr/sbin/rtcwake" >> /etc/sudoers
        ;;
esac


Saturday, April 02, 2011

Remove all Development packages from Debian

Another cool one liner to remove all development packages to clean your Debian.

$ aptitude remove `dpkg -l | grep -e \-dev | sed 's/ii//g' \
| sed 's/rc//g' | sed 's/^ *//;s/ *$//' \
| sed 's/ \+ /\t/g' | cut -f 1`


Remove all GNOME from debian - a one line command

This one is not so easy to follow, but it works for me :-).

Do try only the stuff inside `` (back tick operator in the bash language), to see what it does:

$ aptitude remove `dpkg -l | grep gnome | sed 's/ii//g' \
| sed 's/rc//g' | sed 's/^ *//;s/ *$//' \
| sed 's/ \+ /\t/g' | cut -f 1`


GNOME Fork is dead ...

The EXDE project, which aimed to continue supporting gnome 2.X is dead. This is really a shame,
I wish I could have taken part in it. I really like the user experience that GNOME 2.X offered new comers to Linux, and it was always my default recommendation when I installed a new laptop with Linux to a friend.

I will keep looking for an alternative for GNOME 2.X, and I already expect to start working with XFCE 4.8 on my installed Debian.




Thursday, March 31, 2011

running more than one linux distribution without rebooting ...

My laptop has reached Nirvana with Debian Squeeze, everything works out of the box, and I very happy with the stability of the system. I don't feel the software is outdated, because I anyway install some applications I need or like directly from source.
However, I still want to be able to run Debian testing, and see how my system evolves. Enter "chroot".

With chroot I can run more that one Linux Distro and more than one X-Server with out the need to stop my work and reboot my laptop. This is just great.

Here is how to do it, assuming you already have a partition with a Debian installed on in do the following (if you don't have a partition with Debian installed, I suggest you take a look at "debootstrap"):

1. First make a location where you will work as the root of the new debian, in my case:
$ su -
# mkdir /debian-sec
2. now mount that partition, in my case /dev/sda5:
mount /dev/sda5 /debian-sec
3. enable important devices so the new Debian will work as expected.
mount -o bind /proc /debian-sec/proc
mount -o bind /dev/ /debian-sec/dev/ 
mount /dev/pts /debian-sec/dev/pts -t devpts 
mount -t sysfs /sysfs/ /debian-sec/sys 
4. finally change the root with chroot:
chroot /debian-sec/ /bin/bash
If you want to run a secondary X-Server, do the following inside the chroot:
chroot # vi /etc/gdm/gdm.conf # do s/vt7/vt9/ in [servers] section
chroot # /etc/init.d/gdm start
this will start another X-Server on vt9, to which you can switch with Alt+Ctrl+F9.

Cheerios, Linux and Debian !

UPDATE: The last section about GDM in chroot seems not to work in gdm3...
with gdm3:

chroot # vim /usr/share/gdm/gdm.schemas

change the following keys:
   <schema>
      <key>daemon/FirstVT</key>
      <signature>i</signature>
      <default>9</default>
    </schema>



What does work ?

Switch to tty1, login as root, and chroot into the chrooted debian.
Then chanage to with "su - "

now start the X server as the following:
startx /usr/bin/fluxbox -- :1&
or
startx /usr/bin/gnome-session -- :1&
or
startx  -- :1&


Friday, March 25, 2011

'yes,yes' we can ... on the usefull linux command ...

Recently I started building my own LFS, I was pretty amused by the command 'yes'...

However, today I found a use for that command, when I had to install a binary firmware on multiple servers. The binary is not editable and  expects two times 'yes' to finish the process.
So, the solution is to run on all the computers the following command inside a loop :
'yes | sh binary_firmware.exe' - also, this is a simple example a of parallel programming and pipes.

This little trick saved me quite some typing and waiting in front of the computer !


Thursday, March 03, 2011

Matlab Alternative: RStudio

To the list of great Matlab alternative I add today RSTUDIO.
Although, I usually don't program in R, I am glad to see it is not freezing, and continuously develop as a scientific interested language. I am guessing that this fancy IDE for R, would make it easier to accept among people who are deeply rooted in the EXCELLENT MATLAB IDE.
However, doing most of my scientific tasks, and system administration in python, I think Matlab's syntax is equally weird to that of R ;-).

One weird choice of the developers is to call the binary rdesktop instead of rstudio... Maybe they don't know about rdesktop
which is familiar to most system administrators ... oh, well, I guess I'll have to open a bug ...