Hi, I have moved to a new domain where I will be posting new posts.
The URL is http://blog.sriunplugged.com
Check it Out.
Thursday, December 17, 2009
Thursday, April 16, 2009
Restoring the Grub after reinstalling Windows
After reinstalling windows or fixing MBR(Master Boot Record) you always loose your grub and you cannot boot to your linux. So this post is about the methods of restoring the grub. There are three methods I use. I will explain all three.
All three methods need a live cd of a linux. You need to boot from the live cd and take the terminal and do the following:
All three methods need a live cd of a linux. You need to boot from the live cd and take the terminal and do the following:
- First method is using grub command. We initially go into the grub mode interface using the command
sudo grubThis will get you a "grub>" prompt (i.e. the grub shell). At grub>. enter these commands
find /boot/grub/stage1If the find returned (hd0,1) then you would enter
root (hd0,1)Now the root drive where the boot folder is mounted.Now we needed to setup the drive to boot to show the grub. We do this by
setup (hd0)Finally exit the grub shell
quitAnd then Reboot to and try if you are getting the grub.
If not try the next method.
- If couldn't get grub to find the stage1 file or even recognize the drive. Use this method.
sudo mkdir /mnt/root
sudo mount -t ext3 /dev/sda6 /mnt/root
Then you have to mount the proc subsystem and udev inside /mnt/root also:
sudo mount -t proc none /mnt/root/proc
sudo mount -o bind /dev /mnt/root/dev
Doing this allows grub to discover your drives. Next you have to chroot:
sudo chroot /mnt/root /bin/bash
Now that you're chrooted into your drive as root everything should work.
sudo grubAnd then follow the 1st method to install the grub.
- In lastest Linux you can use the command grub-install.The usage of this command is as
sudo grub-install /dev/sdaIt might be hda if the hard disk is IDE and sda if disk is SATA.
Tuesday, March 17, 2009
Birthday Reminder For Gnome Panel
This program checks the file /home/rsrijith/shell/birthday_reminder.txt to find the upcoming birthdays in 20 days and writes into the file /home/rsrijith/shell/birthdays.
There is a file called /home/rsrijith/shell/birthdays1, the difference between it and birthdays file is that birthdays contains only first name of the person and birthdays1 contains the whole name.
So that's it. Now the code....
This code is part of the Perl Panel Code. The related codes to this are:
There is a file called /home/rsrijith/shell/birthdays1, the difference between it and birthdays file is that birthdays contains only first name of the person and birthdays1 contains the whole name.
So that's it. Now the code....
#!/bin/bash
echo "Birthday Finder ">>/home/rsrijith/logs/bday
date>>/home/rsrijith/logs/bday
tillm=$(date --date="+20 day" +"%b")
nowm=$(date +"%b")
tilld=$(date --date="+20 day" +"%2d")
nowd=$(date +"%d")
nowd=$((10#$nowd))
year=$(date +"%Y")
FileName='/home/rsrijith/shell/birthday_reminder.txt'
if [ -e /home/rsrijith/shell/birthdays ]
then
rm /home/rsrijith/shell/birthdays
fi
touch /home/rsrijith/shell/birthdays
if [ -e /home/rsrijith/shell/birthdays1 ]
then
rm /home/rsrijith/shell/birthdays1
fi
touch /home/rsrijith/shell/birthdays1
while read LINE
do
m=$(echo $LINE|cut -f2 -d',')
d=$(echo $LINE|cut -f3 -d',')
name=$(echo $LINE|cut -f1 -d',')
yob=$(echo $LINE|cut -f4 -d',')
if [ $m == $nowm ]
then
d="${d#0}";
if [ $nowd -le $d ]
then
name1=$name;
name=` echo $name|sed 's/\([^ ]*\).*/\1/;s/\([^.]*\).*/\1/'`
dif=$(($d-$nowd))
yrdif=$(($year-$yob))
if [ $dif -le 1 ]
then
if [ $dif -eq 0 ]
then
echo "Happy Birthday to "$name>>/home/rsrijith/shell/birthdays
echo "Happy Birthday to "$name1>>/home/rsrijith/shell/birthdays1
else
echo "$dif day to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif day to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
else
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
fi
else
if [ $m == $tillm ]
then
if [ $tilld -gt $d ]
then
name1=$name
name=` echo $name|sed 's/\([^ ]*\).*/\1/'`
lastdate=$(date -d "-$(date +%d) days +1 month"|cut -f 3 -d " ")
echo "$d $lastdate $nowd"
dif=$(($d+$lastdate-$nowd))
yrdif=$(($year-$yob))
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
fi
fi
fi
done < $FileName
if [ ! -s /home/rsrijith/shell/birthdays ]
then
echo "Nothing to Remind" > /home/rsrijith/shell/birthdays
fi
cat /home/rsrijith/shell/birthdays1|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays1
cat /home/rsrijith/shell/birthdays|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays
echo "Birthday Finder ">>/home/rsrijith/logs/bday
date>>/home/rsrijith/logs/bday
tillm=$(date --date="+20 day" +"%b")
nowm=$(date +"%b")
tilld=$(date --date="+20 day" +"%2d")
nowd=$(date +"%d")
nowd=$((10#$nowd))
year=$(date +"%Y")
FileName='/home/rsrijith/shell/birthday_reminder.txt'
if [ -e /home/rsrijith/shell/birthdays ]
then
rm /home/rsrijith/shell/birthdays
fi
touch /home/rsrijith/shell/birthdays
if [ -e /home/rsrijith/shell/birthdays1 ]
then
rm /home/rsrijith/shell/birthdays1
fi
touch /home/rsrijith/shell/birthdays1
while read LINE
do
m=$(echo $LINE|cut -f2 -d',')
d=$(echo $LINE|cut -f3 -d',')
name=$(echo $LINE|cut -f1 -d',')
yob=$(echo $LINE|cut -f4 -d',')
if [ $m == $nowm ]
then
d="${d#0}";
if [ $nowd -le $d ]
then
name1=$name;
name=` echo $name|sed 's/\([^ ]*\).*/\1/;s/\([^.]*\).*/\1/'`
dif=$(($d-$nowd))
yrdif=$(($year-$yob))
if [ $dif -le 1 ]
then
if [ $dif -eq 0 ]
then
echo "Happy Birthday to "$name>>/home/rsrijith/shell/birthdays
echo "Happy Birthday to "$name1>>/home/rsrijith/shell/birthdays1
else
echo "$dif day to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif day to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
else
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
fi
else
if [ $m == $tillm ]
then
if [ $tilld -gt $d ]
then
name1=$name
name=` echo $name|sed 's/\([^ ]*\).*/\1/'`
lastdate=$(date -d "-$(date +%d) days +1 month"|cut -f 3 -d " ")
echo "$d $lastdate $nowd"
dif=$(($d+$lastdate-$nowd))
yrdif=$(($year-$yob))
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
fi
fi
fi
done < $FileName
if [ ! -s /home/rsrijith/shell/birthdays ]
then
echo "Nothing to Remind" > /home/rsrijith/shell/birthdays
fi
cat /home/rsrijith/shell/birthdays1|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays1
cat /home/rsrijith/shell/birthdays|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays
This code is part of the Perl Panel Code. The related codes to this are:
Reminder for Gnome Panel
This is the program that lets us to enter the text and time at which it should be reminded me. The command has the following options
- -d: date eg: 17/3/2009
- -t : time [ It's should be entered as 24hr clock] eg: 20:00:00
- -r : reminder text [ It should be entered in between a double quotes ] eg: "This is a test"
- -p :priority [ I hav'nt implemented it yet . Kept it for future implementation.] eg : 1
- -b :Remind me before [ By using it we can change the default remind before time of 5mins ie it is used to remind from a specific mins before the time we have scheduled to remind. It is specified in mins] eg: 5
#!/usr/bin/perl
use Time::Local;
my @date;
my @time;
my $d=0,$t=0,$r=0,$p=0,$b=0;
my @deftime=localtime();
$deftime[5]+=1900;
$deftime[4]++;
my $dv="$deftime[3]/$deftime[4]/$deftime[5]",$tv="$deftime[2]:$deftime[1]:$deftime[0]",$rv="",$pv=1,$bv=0;
foreach $argnum (0 .. $#ARGV)
{
if($ARGV[$argnum] eq "-d")
{
$d=1;
$dv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-t")
{
$t=1;
$tv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-r")
{
$r=1;
$rv=$ARGV[$argnum+1];
print "Remind Text:$rv\n";
}
elsif($ARGV[$argnum] eq "-p")
{
$p=1;
$pv=$ARGV[$argnum+1];
print "Priority:$pv\n";
}
elsif($ARGV[$argnum] eq "-b")
{
$b=1;
$bv=$ARGV[$argnum+1];
print "Remind Before:$bv\n";
}
}
@date=split('/',$dv);
print "Date:$dv\n";
@time={0,0,0};
@time=split(':',$tv);
print "Time:$tv";
$date[1]--;
my $time=timelocal($time[2],$time[1],$time[0],$date[0],$date[1],$date[2],);
my $nowtime=timelocal(localtime());
my $difftime=$time-$nowtime;
print "\nTime Of Alarm:".$time."\nTime Now:".$nowtime."\nDifference in Seconds:".$difftime."\n";
open (FH,">>/home/rsrijith/perl/reminder");
print FH "$time:$pv:$bv:$rv\n";
close FH;
This code is part of the Perl Panel Code. The related codes to this are:use Time::Local;
my @date;
my @time;
my $d=0,$t=0,$r=0,$p=0,$b=0;
my @deftime=localtime();
$deftime[5]+=1900;
$deftime[4]++;
my $dv="$deftime[3]/$deftime[4]/$deftime[5]",$tv="$deftime[2]:$deftime[1]:$deftime[0]",$rv="",$pv=1,$bv=0;
foreach $argnum (0 .. $#ARGV)
{
if($ARGV[$argnum] eq "-d")
{
$d=1;
$dv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-t")
{
$t=1;
$tv=$ARGV[$argnum+1];
}
elsif($ARGV[$argnum] eq "-r")
{
$r=1;
$rv=$ARGV[$argnum+1];
print "Remind Text:$rv\n";
}
elsif($ARGV[$argnum] eq "-p")
{
$p=1;
$pv=$ARGV[$argnum+1];
print "Priority:$pv\n";
}
elsif($ARGV[$argnum] eq "-b")
{
$b=1;
$bv=$ARGV[$argnum+1];
print "Remind Before:$bv\n";
}
}
@date=split('/',$dv);
print "Date:$dv\n";
@time={0,0,0};
@time=split(':',$tv);
print "Time:$tv";
$date[1]--;
my $time=timelocal($time[2],$time[1],$time[0],$date[0],$date[1],$date[2],);
my $nowtime=timelocal(localtime());
my $difftime=$time-$nowtime;
print "\nTime Of Alarm:".$time."\nTime Now:".$nowtime."\nDifference in Seconds:".$difftime."\n";
open (FH,">>/home/rsrijith/perl/reminder");
print FH "$time:$pv:$bv:$rv\n";
close FH;
Backend For Panel Reminder
I had already posted about creating a Display Reminders In Gnome Panel. This post is an addition to that script. This is a backend script that writes what to print into the panel_remind file. I use this script to print Birthday Reminder and Things to remember of which I will be posting shortly.
So the Code is simple Perl script.
So the ordinary panel reminder can be made of some use using this script.
So try it out and tell me how it went.
So the Code is simple Perl script.
#!/usr/bin/perl
our $printl;our $i=0;our $r=0;
$| = 1;
while(TRUE)
{
open (RB,"/home/rsrijith/perl/reminder");
my @line=<RB>;
close RB;
if($line[0])
{
while($line[$i])
{
open (WR,">/home/rsrijith/panel_remind");
my @s=split(":",$line[$i]);
my $nowtime=timelocal(localtime());
my $a=$s[2]+300;
if(($s[0]-$nowtime<=$a)&&($s[0]-$nowtime>=0))
{
my $t= to_int((($s[0]-$nowtime)/60));
while($t>0)
{
open (WR,">/home/rsrijith/panel_remind");
print WR "Red:In $t Mins - $s[3]";
close WR;
$r=1;
$t--;
sleep(60);
if( $t == 0)
{ `notify-send "$s[3]" -u critical -t 60000`}
}
}
open (WB,">/home/rsrijith/perl/reminder");
my $nowtime=timelocal(localtime());
if($s[0]-$nowtime>0)
{
print WB "$line[$i]";
close WB;
}
$i++;
}
if($r eq 0)
{
bday();
}
$i=0;
}
else
{
print "Birthday";
bday();
}
}
sub bday
{
open (RB,"/home/rsrijith/shell/birthdays");
my @line=<RB>;
close RB;
if((!$line[0])&&($r==0))
{
print "nothing to remind";
$printl="Black:Nothing to Remind \n:(";
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
sleep(100);
}
while($line[$i])
{
$_=$line[$i];
if(m/Happy/)
{
$printl="Blue:$line[$i]";
}
else
{
$printl="Black:$line[$i]";
}
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
$i++;
sleep(5);
}
$i=0;
return;
}
This script reads from filesour $printl;our $i=0;our $r=0;
$| = 1;
while(TRUE)
{
open (RB,"/home/rsrijith/perl/reminder");
my @line=<RB>;
close RB;
if($line[0])
{
while($line[$i])
{
open (WR,">/home/rsrijith/panel_remind");
my @s=split(":",$line[$i]);
my $nowtime=timelocal(localtime());
my $a=$s[2]+300;
if(($s[0]-$nowtime<=$a)&&($s[0]-$nowtime>=0))
{
my $t= to_int((($s[0]-$nowtime)/60));
while($t>0)
{
open (WR,">/home/rsrijith/panel_remind");
print WR "Red:In $t Mins - $s[3]";
close WR;
$r=1;
$t--;
sleep(60);
if( $t == 0)
{ `notify-send "$s[3]" -u critical -t 60000`}
}
}
open (WB,">/home/rsrijith/perl/reminder");
my $nowtime=timelocal(localtime());
if($s[0]-$nowtime>0)
{
print WB "$line[$i]";
close WB;
}
$i++;
}
if($r eq 0)
{
bday();
}
$i=0;
}
else
{
print "Birthday";
bday();
}
}
sub bday
{
open (RB,"/home/rsrijith/shell/birthdays");
my @line=<RB>;
close RB;
if((!$line[0])&&($r==0))
{
print "nothing to remind";
$printl="Black:Nothing to Remind \n:(";
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
sleep(100);
}
while($line[$i])
{
$_=$line[$i];
if(m/Happy/)
{
$printl="Blue:$line[$i]";
}
else
{
$printl="Black:$line[$i]";
}
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
$i++;
sleep(5);
}
$i=0;
return;
}
- /home/rsrijith/shell/birthdays: The file contains birthdays of my friends that I need to be reminded of. The method to print the upcoming birthdays into this file is posted at <will be posted soon>.
- /home/rsrijith/perl/reminder:The file contains reminders that I need to be reminded. I used another script to write into that file which is posted at <will be posted soon >.
So the ordinary panel reminder can be made of some use using this script.
So try it out and tell me how it went.
Saturday, March 14, 2009
Auto Away Notifier for Pidgin in Perl
Whenever I am away from laptop my chat buddies leave me lots message and finally lots of "You there???". So I thought of making a script that would inform my buddies that I am away when someone sends me a message.
This method works with Pigin API.
I have used /proc/acpi/button/lid/C267/state file to find if the lib of the laptop is closed or not. This file may vary in your laptop. So try to find the find the file in your computer that stores the status of the lid. It should be a file in /proc/acpi/button/lid/ folder and replace the file accordingly in your computer.
The Content of /proc/acpi/button/lid/C267/state is state: open and state: closed when the lid was closed.
We save this file as /usr/lib/purple-2/autonotifier.pl and use chmod +x /usr/lib/purple-2/test.pl to give the plugin execute permission. Now restart the Pidgin if it is running or open pidgin and go to Tools->Plugins and you should see a plugin named "Auto Away Plugin". Activate it and that's it.
I have used /sys/class/leds/b43-phy0\:\:radio/brightness file to notify me if there is any messages while i was away. It uses my Wi-fi light to notify me. When there is a message then the Wi-fi light blinks. This too is computer specific so find the file that controls any of the unused leds and replace that file too.
So try it out and comment me on how it went.
This method works with Pigin API.
I have used /proc/acpi/button/lid/C267/state file to find if the lib of the laptop is closed or not. This file may vary in your laptop. So try to find the find the file in your computer that stores the status of the lid. It should be a file in /proc/acpi/button/lid/ folder and replace the file accordingly in your computer.
The Content of /proc/acpi/button/lid/C267/state is state: open and state: closed when the lid was closed.
We save this file as /usr/lib/purple-2/autonotifier.pl and use chmod +x /usr/lib/purple-2/test.pl to give the plugin execute permission. Now restart the Pidgin if it is running or open pidgin and go to Tools->Plugins and you should see a plugin named "Auto Away Plugin". Activate it and that's it.
I have used /sys/class/leds/b43-phy0\:\:radio/brightness file to notify me if there is any messages while i was away. It uses my Wi-fi light to notify me. When there is a message then the Wi-fi light blinks. This too is computer specific so find the file that controls any of the unused leds and replace that file too.
use Purple;
%PLUGIN_INFO = (
perl_api_version => 2,
name => "Auto Away Plugin",
version => "0.1",
summary => "Auto Away Notifier",
description => "Auto Away Notifier in Perl",
author => "R.Srijith <rsrijith007\@gmail.com",
url => "http://sriunplugged.blogspot.com",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub im_received {
my ($account, $sender, $message, $conv, $flags) = @_;
Purple::Debug::info("autonotify", "Message recieved\n");
$conv1 = Purple::Conversation->new(1, $account, $sender);
open FILE, ">>/home/rsrijith/logs/autonotifier.txt" or die $!;
open LID, "</proc/acpi/button/lid/C267/state" or die $!;
#$message=~s/<.*>//g;
while(<LID>)
{
if($_ =~ m/closed/)
{
print FILE "$sender:$message\n";
$im = $conv1->get_im_data();
if ($im) { print "ok.\n"; } else { print "fail.\n"; }
system('(if [ ! -e /var/lock/autoremind ]; then while grep -m 1 -q closed /proc/acpi/button/lid/C267/state; do touch /var/lock/autoremind; sleep 1; echo -n 0 >/sys/class/leds/b43-phy0\:\:radio/brightness; sleep 1;echo -n 1 >/sys/class/leds/b43-phy0\:\:radio/brightness; done; if [ -e /var/lock/autoremind ]; then rm /var/lock/autoremind; fi; fi)&');
$im->send("This is an automated response system: R Srijith is not at the desk rite now.");
}
}
close FILE;
}
sub plugin_load {
$plugin = shift;
$conversation_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, \&im_received, $data);
Purple::Debug::info("autonotify", "Auto Notify Loaded\n");
}
sub plugin_unload {
Purple::Debug::info("autonotify", "Auto Notify Unloaded\n");
}
%PLUGIN_INFO = (
perl_api_version => 2,
name => "Auto Away Plugin",
version => "0.1",
summary => "Auto Away Notifier",
description => "Auto Away Notifier in Perl",
author => "R.Srijith <rsrijith007\@gmail.com",
url => "http://sriunplugged.blogspot.com",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub im_received {
my ($account, $sender, $message, $conv, $flags) = @_;
Purple::Debug::info("autonotify", "Message recieved\n");
$conv1 = Purple::Conversation->new(1, $account, $sender);
open FILE, ">>/home/rsrijith/logs/autonotifier.txt" or die $!;
open LID, "</proc/acpi/button/lid/C267/state" or die $!;
#$message=~s/<.*>//g;
while(<LID>)
{
if($_ =~ m/closed/)
{
print FILE "$sender:$message\n";
$im = $conv1->get_im_data();
if ($im) { print "ok.\n"; } else { print "fail.\n"; }
system('(if [ ! -e /var/lock/autoremind ]; then while grep -m 1 -q closed /proc/acpi/button/lid/C267/state; do touch /var/lock/autoremind; sleep 1; echo -n 0 >/sys/class/leds/b43-phy0\:\:radio/brightness; sleep 1;echo -n 1 >/sys/class/leds/b43-phy0\:\:radio/brightness; done; if [ -e /var/lock/autoremind ]; then rm /var/lock/autoremind; fi; fi)&');
$im->send("This is an automated response system: R Srijith is not at the desk rite now.");
}
}
close FILE;
}
sub plugin_load {
$plugin = shift;
$conversation_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, \&im_received, $data);
Purple::Debug::info("autonotify", "Auto Notify Loaded\n");
}
sub plugin_unload {
Purple::Debug::info("autonotify", "Auto Notify Unloaded\n");
}
So try it out and comment me on how it went.
Saturday, February 7, 2009
Display Reminders In Gnome Panel
It was a long standing requirement of mine to create a reminder software or something which can keep me reminding of things as I always keep forgetting things. So I made a reminder that displays my reminders on the Gnome Panel.
It looks something like this:
So how do we do it?
1st of all we need to display the program we need in the Add to Panel.
For that we add to the bonobo server list. We do this by adding the following code in the folder /usr/lib/bonobo/servers/. Let us name the file as GNOME_PerlApplet.server
The content of this file should be :
The program need the Following packages:
Perl packages:
Linux Package:
An Example of the content of that file should be as
Comment me if you have any doubts or if it's not working.
It looks something like this:
So how do we do it?
1st of all we need to display the program we need in the Add to Panel.
For that we add to the bonobo server list. We do this by adding the following code in the folder /usr/lib/bonobo/servers/. Let us name the file as GNOME_PerlApplet.server
The content of this file should be :
<oaf_info>
<oaf_server iid="OAFIID:PerlSampleApplet_Factory" type="exe" location="/home/rsrijith/perl/panel-applet">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/GenericFactory:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Panel Reminder"/>
<oaf_attribute name="description" type="string" value="Perl Program working in Panel"/>
</oaf_server>
<oaf_server iid="OAFIID:PerlSampleApplet" type="factory" location="OAFIID:PerlSampleApplet_Factory">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Panel Reminder"/>
<oaf_attribute name="description" type="string" value="Perl Program working in Panel:R Srijith"/>
<oaf_attribute name="panel:category" type="string" value="Amusements"/>
<oaf_attribute name="panel:icon" type="string" value="bug-buddy.png"/>
</oaf_server>
</oaf_info>
So this specifies the location of the perl file to run on adding this applet. So here it is /home/rsrijith/perl/panel-applet . This file should print the reminders to be printed on the panel.<oaf_server iid="OAFIID:PerlSampleApplet_Factory" type="exe" location="/home/rsrijith/perl/panel-applet">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/GenericFactory:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Panel Reminder"/>
<oaf_attribute name="description" type="string" value="Perl Program working in Panel"/>
</oaf_server>
<oaf_server iid="OAFIID:PerlSampleApplet" type="factory" location="OAFIID:PerlSampleApplet_Factory">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Panel Reminder"/>
<oaf_attribute name="description" type="string" value="Perl Program working in Panel:R Srijith"/>
<oaf_attribute name="panel:category" type="string" value="Amusements"/>
<oaf_attribute name="panel:icon" type="string" value="bug-buddy.png"/>
</oaf_server>
</oaf_info>
The program need the Following packages:
Perl packages:
- ExtUtils::Depends
- ExtUtils::PkgConfig
- Gnome2::GConf
- Gnome2::PanelApplet
sudo perl -MCPAN -e 'install <package-name>'
Linux Package:
- libpanelappletmm-2.6-1c2
- libpanelappletmm-2.6-dev
sudo apt-get install <package-name>
#!/usr/bin/perl -w
use warnings;
use utf8;
use Gnome2::PanelApplet;
Gnome2::Program->init ('A Stupid Applet Written in Perl', '0.01', 'libgnomeui',
sm_connect => FALSE);
Gnome2::PanelApplet::Factory->main ('OAFIID:PerlSampleApplet_Factory',
'Gnome2::PanelApplet',
\&fill);
sub fill {
my ($applet, $iid, $data) = @_;
if ($iid ne 'OAFIID:PerlSampleApplet') {
return FALSE;
}
my $menu_xml = <<EOX;
<popup name="button3">
<menuitem name="Properties Item"
verb="Birthdays"
_label="Birthdays"
pixtype="stock"
pixname="gtk-properties"/>
<menuitem name="DesktopSwitcher Item"
verb="DesktopSwitcher"
_label="Wallpaper Switcher"
pixtype="stock"
pixname="gtk-stock"/>
<menuitem name="Walldelete Item"
verb="Walldelete"
_label="Wallpaper Delete"
pixtype="stock"
pixname="gtk-stock"/>
<menuitem name="About Item"
verb="About"
_label="About"
pixtype="stock"
pixname="gnome-stock-about"/>
</popup>
EOX
my $cb_mapping = {
Birthdays => [\&properties_callback, 'default!'],
DesktopSwitcher => \&deskswitcher_callback,
Walldelete => \&walldelete_callback,
About => \&about_callback,
};
$applet->setup_menu($menu_xml, $cb_mapping, 'default?');
our $i=0;our @line;
our $label = Gtk2::Label->new;
$label->set_justify("left");
$label->set_line_wrap(TRUE);
$label->modify_font(Gtk2::Pango::FontDescription->from_string("Monospace 10"));
$label->modify_fg("normal", Gtk2::Gdk::Color->parse("Black"));
$applet->add ($label);
$applet->show_all;
Glib::Timeout->add (5000, \&update_value);
#Glib::Timeout->add (500, \&update_list);
sub update_list{
open FILE,"/home/rsrijith/panel_remind";
@line=<FILE>;
close FILE;
}
sub update_value
{
my @string=split(':',$line[0]);
$label->modify_fg("normal", Gtk2::Gdk::Color->parse($string[0]));
$label->set_markup("\n".$string[1]);
update_list();
}
}
sub deskswitcher_callback
{
system('/home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/desktopbackground');
}
sub walldelete_callback
{
system('/home/rsrijith/shell/deletewall 2>>/home/rsrijith/logs/desktopbackground');
}
sub properties_callback {
my $b="";
open BDAY,"/home/rsrijith/shell/birthdays1";
while(<BDAY>)
{ $b.=$_."\n";
}
my $dialog = Gtk2::MessageDialog->new (undef, [],
'info', 'ok',
$b);
$dialog->run;
$dialog->destroy;
}
sub about_callback {
my $about = Gnome2::About->new ('Panel Reminder', '0.1',
'Perl Program working in Panel',
'© 2009 R.Srijith',
'R.Srijith <rsrijith007@gmail.com');
$about->show;
}
This program prints the contents of /home/rsrijith/panel_reminduse warnings;
use utf8;
use Gnome2::PanelApplet;
Gnome2::Program->init ('A Stupid Applet Written in Perl', '0.01', 'libgnomeui',
sm_connect => FALSE);
Gnome2::PanelApplet::Factory->main ('OAFIID:PerlSampleApplet_Factory',
'Gnome2::PanelApplet',
\&fill);
sub fill {
my ($applet, $iid, $data) = @_;
if ($iid ne 'OAFIID:PerlSampleApplet') {
return FALSE;
}
my $menu_xml = <<EOX;
<popup name="button3">
<menuitem name="Properties Item"
verb="Birthdays"
_label="Birthdays"
pixtype="stock"
pixname="gtk-properties"/>
<menuitem name="DesktopSwitcher Item"
verb="DesktopSwitcher"
_label="Wallpaper Switcher"
pixtype="stock"
pixname="gtk-stock"/>
<menuitem name="Walldelete Item"
verb="Walldelete"
_label="Wallpaper Delete"
pixtype="stock"
pixname="gtk-stock"/>
<menuitem name="About Item"
verb="About"
_label="About"
pixtype="stock"
pixname="gnome-stock-about"/>
</popup>
EOX
my $cb_mapping = {
Birthdays => [\&properties_callback, 'default!'],
DesktopSwitcher => \&deskswitcher_callback,
Walldelete => \&walldelete_callback,
About => \&about_callback,
};
$applet->setup_menu($menu_xml, $cb_mapping, 'default?');
our $i=0;our @line;
our $label = Gtk2::Label->new;
$label->set_justify("left");
$label->set_line_wrap(TRUE);
$label->modify_font(Gtk2::Pango::FontDescription->from_string("Monospace 10"));
$label->modify_fg("normal", Gtk2::Gdk::Color->parse("Black"));
$applet->add ($label);
$applet->show_all;
Glib::Timeout->add (5000, \&update_value);
#Glib::Timeout->add (500, \&update_list);
sub update_list{
open FILE,"/home/rsrijith/panel_remind";
@line=<FILE>;
close FILE;
}
sub update_value
{
my @string=split(':',$line[0]);
$label->modify_fg("normal", Gtk2::Gdk::Color->parse($string[0]));
$label->set_markup("\n".$string[1]);
update_list();
}
}
sub deskswitcher_callback
{
system('/home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/desktopbackground');
}
sub walldelete_callback
{
system('/home/rsrijith/shell/deletewall 2>>/home/rsrijith/logs/desktopbackground');
}
sub properties_callback {
my $b="";
open BDAY,"/home/rsrijith/shell/birthdays1";
while(<BDAY>)
{ $b.=$_."\n";
}
my $dialog = Gtk2::MessageDialog->new (undef, [],
'info', 'ok',
$b);
$dialog->run;
$dialog->destroy;
}
sub about_callback {
my $about = Gnome2::About->new ('Panel Reminder', '0.1',
'Perl Program working in Panel',
'© 2009 R.Srijith',
'R.Srijith <rsrijith007@gmail.com');
$about->show;
}
An Example of the content of that file should be as
Blue:Happy Birthday to Mahima
So that's it!! And Happy Birthday Mahima.Comment me if you have any doubts or if it's not working.
Sunday, February 1, 2009
BSNL Dataone Auto Downloader
Bsnl(India) provides an account that has 2am to 8am unlimited download. It was not easy to wake up at 2am and switch on the computer and sleep again. So I tried to find a method to switch on the computer automatically at 2am and download and shutdown at 8am. Although the I thought the idea was foolish, I found out that there actually is a method for doing it. "ACPI Alarm" was introduced in 1999 or so (Even my old PC had it).
So what does this alarm do? The ACPI alarm wakes up the computer from shutdown or hibernate. You need to keep the UPS or Power Plug to the CPU on after scheduling the time in ACPI or it gets reseted.
This function needs Bios Support and I feel most bios supports this feature.
The method to do this depends on your kernel version.
So check the Kernel Version first using the command.
If Kernel > 2.6.22 and higher use /sys/class/rtc/rtc0/wakealarm
Kernel < 2.6.21 and lower use /proc/acpi/alarm
Disable hwclock updates
On most machines it's required to make a small change to the Linux shutdown procedure. When your machine goes down, most linux distributions write the system time/data back to the bios. On MANY machines the machines never wakes-up after a time/data update. It's recommended to make this change before you start. See below for more details (distro specific),
The reason for the recommendation above is that most linux distributions write the current system time back to the bios when shutting down the machine, and with some BIOSes, the machine will not wake up if the hardware clock is modified after the alarm timer has been set. To avoid that, it is necessary to disable the writing of the current system time to the hardware clock in the system shutdown scripts. This is distribution specific, so here are some examples:
modifying
/etc/default/rcS
Gentoo Set clock_systohc to "NO" in
/etc/conf.d/clock
modifying
/etc/sysconfig/clock
modifying
/etc/init.d/halt
Check that you can write a new time to the RTC Clock Alarm (you will need to be Root) Format is YYYY-MM-DD HH:MM:SS
Beginning with kernel 2.6.22 /proc/acpi/alarm has been removed and replaced with /sys/class/rtc/rtc0/wakealarm. The key differences with the wakealarm interface are:
An example of setting alarm is as follows
Then we can confirm that the alarm is set with the following.
If the alarm is set then you should see something like this. If so then shutdown and see if it wakes up at the alarm date/time.
Ok, so the Basic of ACPI is done.Now lets see how we switch on the computer at 2am.
We use the command as,
Rebooting modem is required as Dataone calculates session from On time to Off time. If the modem is up from 1am to 5am and we download 4gb, what the dataone does is, it takes the total time modem was on ie 4 hours. 2am to 5am is free so the non free time is 1hr so we will be charged for 1gb (4gb/4 hours). So it's essential to reboot the modem at 2am.
The code to reboot is ,
We should run this command in sessions so that it runs at each boot.
We do this by Adding in
System -> Preferences -> Sessions -> Add
Give the path of the File that contains the above script. That's it!! Done!!. The script starts at 2am. Now we need to stop the script at 8am.
We use following code for that,
Well Happy Downloading!! Keep me Posted on how it went.
So what does this alarm do? The ACPI alarm wakes up the computer from shutdown or hibernate. You need to keep the UPS or Power Plug to the CPU on after scheduling the time in ACPI or it gets reseted.
This function needs Bios Support and I feel most bios supports this feature.
The method to do this depends on your kernel version.
So check the Kernel Version first using the command.
uname -r
If Kernel > 2.6.22 and higher use /sys/class/rtc/rtc0/wakealarm
Kernel < 2.6.21 and lower use /proc/acpi/alarm
Disable hwclock updates
On most machines it's required to make a small change to the Linux shutdown procedure. When your machine goes down, most linux distributions write the system time/data back to the bios. On MANY machines the machines never wakes-up after a time/data update. It's recommended to make this change before you start. See below for more details (distro specific),
The reason for the recommendation above is that most linux distributions write the current system time back to the bios when shutting down the machine, and with some BIOSes, the machine will not wake up if the hardware clock is modified after the alarm timer has been set. To avoid that, it is necessary to disable the writing of the current system time to the hardware clock in the system shutdown scripts. This is distribution specific, so here are some examples:
modifying
/etc/default/rcS
with the following will fix this problem: # # /etc/default/rcS # # Default settings for the scripts in /etc/rcS.d/ # # For information about these variables see the rcS(5) manual page. # # This file belongs to the "initscripts" package. TMPTIME=0 SULOGIN=no DELAYLOGIN=no UTC=no VERBOSE=no FSCKFIX=no ==> HWCLOCKACCESS=no
/etc/conf.d/clock
: # Set CLOCK to "UTC" if your system clock is set to UTC (also known as # Greenwich Mean Time). If your clock is set to the local time, then # set CLOCK to "local". Note that if you dual boot with Windows, then # you should set it to "local". clock="UTC" # If you want to set the Hardware Clock to the current System Time # during shutdown, then say "YES" here. # You normally don't need to do this if you run a ntp daemon. clock_systohc="NO" # If you wish to pass any other arguments to hwclock during bootup, # you may do so here. Alpha users may wish to use --arc or --srm here. clock_args=""
modifying
/etc/sysconfig/clock
holds a switch to write back system time to the hardware clock # Set to "-u" if your system clock is set to UTC, and to "--localtime"
# if your clock runs that way.
#
HWCLOCK="-u"
SYSTOHC="no"
# Is set to "yes" write back the system time to the hardware
# clock at reboot or shutdown. Usefull if hardware clock is
# much more inaccurate than system clock. Set to "no" if
# system time does it wrong due e.g. missed timer interrupts.
# If set to "no" the hardware clock adjust feature is also
# skipped because it is rather useless without writing back
# the system time to the hardware clock.
modifying
/etc/init.d/halt
with the following will fix this problem: ==> ACPITIME=`cat /proc/acpi/alarm`
[ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
==> echo "$ACPITIME" > /proc/acpi/alarm
Using /proc/acpi/alarm for Kernel 2.6.21 and lower
Check that you can write a new time to the RTC Clock Alarm (you will need to be Root) Format is YYYY-MM-DD HH:MM:SS
echo "2009-02-1 02:00:00" > /proc/acpi/alarm
Using /sys/class/rtc/rtc0/wakealarm
Beginning with kernel 2.6.22 /proc/acpi/alarm has been removed and replaced with /sys/class/rtc/rtc0/wakealarm. The key differences with the wakealarm interface are:
- Instead of accepting a formatted time, wakealarm accepts the number of seconds since Jan 1, 1970.
- If you want to change the wakealarm time, you first need to reset the time.
- You have to make sure that your bios clock is set to UTC time not localtime otherwise it will wakeup at the wrong time. None the less it is still possible if the bios clock is set to localtime (likely if you also run windows), see the section below for how to set the alarm correctly when the bios clock is in localtime.
An example of setting alarm is as follows
echo 0 > /sys/class/rtc/rtc0/wakealarm
date -u --date "Jul 1, 2008 10:32:00" +%s > /sys/class/rtc/rtc0/wakealarm
date -u --date "Jul 1, 2008 10:32:00" +%s > /sys/class/rtc/rtc0/wakealarm
Then we can confirm that the alarm is set with the following.
cat /proc/driver/rtc
If the alarm is set then you should see something like this. If so then shutdown and see if it wakes up at the alarm date/time.
rtc_time : 13:40:26
rtc_date : 2008-12-21
alrm_time : 10:45:00
alrm_date : 2008-12-22
alarm_IRQ : yes
alrm_pending : no
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : no
DST_enable : no
periodic_freq : 1024
batt_status : okay
If you see the alarm date similar to ****-12-21 then the alarm is set to a time in the past and it won't wake up.rtc_date : 2008-12-21
alrm_time : 10:45:00
alrm_date : 2008-12-22
alarm_IRQ : yes
alrm_pending : no
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : no
DST_enable : no
periodic_freq : 1024
batt_status : okay
rtc_time : 13:42:01
rtc_date : 2008-12-21
alrm_time : 13:46:59
alrm_date : ****-12-21
alarm_IRQ : no
alrm_pending : no
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : no
DST_enable : no
periodic_freq : 1024
batt_status : okay
In most systems this method should work. But in some Bios called as Fussy Bios using this function is tough. Lets see the different problems it might have and it's solutionrtc_date : 2008-12-21
alrm_time : 13:46:59
alrm_date : ****-12-21
alarm_IRQ : no
alrm_pending : no
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : no
DST_enable : no
periodic_freq : 1024
batt_status : okay
- Disable/Enable RTC in BIOS
In some cases you need to disable the RTC alarm function is the bios to make things work.
* Another possible glitch is, that the option 'Resume By Alarm' (or whatever it is called) is set to Enabled but wake up using /proc/acpi/alarm only works if the option is set to Disabled. Sounds weird but works with some boards.
* On many boards, when the RTC setting is enabled in the BIOS, it will wake only from a time set and saved from BIOS setup, and not from a time set outside of the BIOS setup environment - as we want. All of the boards the original author of this document needed this setting disabled to correctly wake with ACPI. This is the recommended starting point. - Time/Date not visible in BIOS
After you have set the RTC alarm from Linux, it could be that you not see changes in the BIOS but it still works. - Required to write time/date two times
Some users reported that their BIOS is only updated after writing 2 times to the alarm file. (reported with proc/acpi/alarm)
Ok, so the Basic of ACPI is done.Now lets see how we switch on the computer at 2am.
We use the command as,
- If it's to be set on the next day 2pm :
date +'%a %b %d 02:00:00 GMT %Y' -d '+1 day'|xargs -i date '+%s' -d''{}'' > /sys/class/rtc/rtc0/wakealarm - If it's to be set on the same day 2pm :
date +'%a %b %d 02:00:00 GMT %Y' |xargs -i date '+%s' -d''{}'' > /sys/class/rtc/rtc0/wakealarm
Rebooting modem is required as Dataone calculates session from On time to Off time. If the modem is up from 1am to 5am and we download 4gb, what the dataone does is, it takes the total time modem was on ie 4 hours. 2am to 5am is free so the non free time is 1hr so we will be charged for 1gb (4gb/4 hours). So it's essential to reboot the modem at 2am.
The code to reboot is ,
#!/bin/bash
now=$(date +"%H")
now=${now#0};
if (( $now < 8 )) && (( $now > 1 ))
then
(echo "admin";
sleep 1;
echo "admin";
sleep 1;
echo "13";
sleep 1;
echo "1";
sleep 40;
)|telnet 192.168.1.1
deluge &
fi
deluge is torrent client I use.now=$(date +"%H")
now=${now#0};
if (( $now < 8 )) && (( $now > 1 ))
then
(echo "admin";
sleep 1;
echo "admin";
sleep 1;
echo "13";
sleep 1;
echo "1";
sleep 40;
)|telnet 192.168.1.1
deluge &
fi
We should run this command in sessions so that it runs at each boot.
We do this by Adding in
System -> Preferences -> Sessions -> Add
Give the path of the File that contains the above script. That's it!! Done!!. The script starts at 2am. Now we need to stop the script at 8am.
We use following code for that,
#!/bin/bash
now=$(date +"%H")
date +'%a %b %d 02:00:00 GMT %Y' -d '+1 day'|xargs -i date '+%s' -d''{}'' > /sys/class/rtc/rtc0/wakealarm
sudo killall deluge
sleep 5;
(echo "admin";
sleep 1;
echo "admin";
sleep 1;
echo "13";
sleep 1;
echo "1";
sleep 40;
)|telnet 192.168.1.1
sudo shutdown -h now
We use the crontab to schedule and run it at 7 59am. If you are not sure how to write a crontab entry see the posts before.now=$(date +"%H")
date +'%a %b %d 02:00:00 GMT %Y' -d '+1 day'|xargs -i date '+%s' -d''{}'' > /sys/class/rtc/rtc0/wakealarm
sudo killall deluge
sleep 5;
(echo "admin";
sleep 1;
echo "admin";
sleep 1;
echo "13";
sleep 1;
echo "1";
sleep 40;
)|telnet 192.168.1.1
sudo shutdown -h now
Well Happy Downloading!! Keep me Posted on how it went.
Sunday, November 16, 2008
Online Version of Perl Invisible FInder
Here is the online version invisible finder for gmail.
Felt a lot of people needs this.
Hope it is helpful
And please dont believe it's something foolish to get password. I need to login to get the invisible user List.
And login 2 times atleast and see only the common users in both time. This is because it sometimes gives some false results ie only less than 10%
Happy Picking Hiding People.
Now you can Run but cant hide :P
There is a Problem with the server I had been using the script does'nt work now as the server blocks opening of the 5222 port, which is needed for the script's working.I am trying to find an alternative server.In the mean time you can try running the script on your computer.The script I have used is Find Invisible Users In Gmail
Felt a lot of people needs this.
Hope it is helpful
And please dont believe it's something foolish to get password. I need to login to get the invisible user List.
And login 2 times atleast and see only the common users in both time. This is because it sometimes gives some false results ie only less than 10%
Happy Picking Hiding People.
Now you can Run but cant hide :P
There is a Problem with the server I had been using the script does'nt work now as the server blocks opening of the 5222 port, which is needed for the script's working.I am trying to find an alternative server.In the mean time you can try running the script on your computer.The script I have used is Find Invisible Users In Gmail
Automatic Desktop Wallpaper Changer
I have a lot of wallpaper that I wanted to switch automatically. After a lot of search i found that there a command way to control all the gnome settings. So I the command I used is "gconftool-2".
So code is like:
I have used the DBUS_SESSION variable to make it compatible with Ubuntu 8.10. The Dbus session is a bit bit different from earlier versions. The change is that it does'nt accept the change until the gnome is restarted. It's due to the new session that is made each time you update that value.
So the folder variable should the folder where the wallpapers should lie. You can put pictures in folders inside that folder. All of it will be taken. But I have specified to take only jpg and jpeg only.Now a random image is picked from that using the environment variable $RANDOM. Next we update the gnome settings using gconftool-2 if that image was'nt used in the last 50 changes.
Thus this file picks an image and puts it as wallpaper. So the next part is making this change automatically. For this we use cron (linux scheduler).
Use the command below to enter the crontab
Anyone tried? Worked? Comment me !!!
So code is like:
#!/bin/bash
folder="/home/rsrijith/Pics" #folder where the pics lie in
find $folder -iregex ".*.jp.?g" >$folder/temp_back #list all images in the folder
no=$(cat $folder/temp_back|wc -l)
rand=$(echo `expr $RANDOM % $no`)
while ( grep -q $rand $folder/.last50 )
do
rand=$(echo `expr $RANDOM % $no`)
done
echo $rand >> $folder/.last50
tail -50 $folder/.last50 >$folder/temp
cat $folder/temp >$folder/.last50
rm $folder/temp
file=$(sed -n $rand'p' $folder/temp_back)
ON_USER=rsrijith #your username here
export DBUS_SESSION=$(grep -v "^#" /home/$ON_USER/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)
sudo -u $ON_USER $DBUS_SESSION /usr/bin/gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$file" && echo "Worked On:"$(date) >>/home/$ON_USER/logs/desktopbackground
echo "Set Wallpaper as:"$file >>/home/$ON_USER/logs/desktopbackground
rm $folder/temp_back
folder="/home/rsrijith/Pics" #folder where the pics lie in
find $folder -iregex ".*.jp.?g" >$folder/temp_back #list all images in the folder
no=$(cat $folder/temp_back|wc -l)
rand=$(echo `expr $RANDOM % $no`)
while ( grep -q $rand $folder/.last50 )
do
rand=$(echo `expr $RANDOM % $no`)
done
echo $rand >> $folder/.last50
tail -50 $folder/.last50 >$folder/temp
cat $folder/temp >$folder/.last50
rm $folder/temp
file=$(sed -n $rand'p' $folder/temp_back)
ON_USER=rsrijith #your username here
export DBUS_SESSION=$(grep -v "^#" /home/$ON_USER/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)
sudo -u $ON_USER $DBUS_SESSION /usr/bin/gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$file" && echo "Worked On:"$(date) >>/home/$ON_USER/logs/desktopbackground
echo "Set Wallpaper as:"$file >>/home/$ON_USER/logs/desktopbackground
rm $folder/temp_back
I have used the DBUS_SESSION variable to make it compatible with Ubuntu 8.10. The Dbus session is a bit bit different from earlier versions. The change is that it does'nt accept the change until the gnome is restarted. It's due to the new session that is made each time you update that value.
So the folder variable should the folder where the wallpapers should lie. You can put pictures in folders inside that folder. All of it will be taken. But I have specified to take only jpg and jpeg only.Now a random image is picked from that using the environment variable $RANDOM. Next we update the gnome settings using gconftool-2 if that image was'nt used in the last 50 changes.
Thus this file picks an image and puts it as wallpaper. So the next part is making this change automatically. For this we use cron (linux scheduler).
Use the command below to enter the crontab
sudo crontab -e
Enter the crontab entry as*/15 * * * * /home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/deskbackground
Check the entry usingsudo crontab -l
That's all!!!Anyone tried? Worked? Comment me !!!
Sunday, September 21, 2008
Find Invisible Users In Gmail
Finding who is invisible is something that I always wanted to do.It's always fun to ping a person who feels none can see him/her online. While studying XMPP protocol I found out that even when the person is offline the chat client knows that person is online.
The Chat Client should know who all are really online at any given time.This is because even when the person is invisible he/she should have a buddy list showing online users.
Ah!! Guess you did'nt understand a word till now.Let me try making it simpler.
Let's assume two users A and B are online now.Both A and B are Available (ie the chat client shows them online).Both A and B has a list of online users in his chat client(eg:google talk,gmail inbox chat,pidgin). Now this online users need to be kept constantly updated. This is done by the XMPP protocol(this is the protocol used by google for it's chat).Now even if B is invisible still it needs to keep it's online users list updated as it needs to show B the online users.
So whenever B logs into his account it initially sends a presence notification to all the users in it's contacts list saying that B is online as "Please show me online in our online user list".
All online users respond back with their online status and status message.
This is where the invisible people shows up.The chat server replies back with their status. The only difference in them is that they respond with their status as "Unavailable".
So my aim was to find out all users that respond back to me with Unavailable status and display them.
Ok enough of explanation of how it works let's see the code
#!/bin/perl
use strict;
use Net::XMPP;
my $sttime=time;
print "Username:$ARGV[0]\n";
my $username = "$ARGV[0]";
my $password = "$ARGV[1]";
my $resource = "SNIFFER";
my $hostname = 'talk.google.com';
my $port = 5222;
my $componentname = 'gmail.com';
my $Contype = 'tcpip';
my $tls = 1;
my %online;
my $Con = new Net::XMPP::Client();
$Con->SetCallBacks(presence=>\&presence_ch);
my $status = $Con->Connect(
hostname => $hostname, port => $port,
componentname => $componentname,
connectiontype => $Contype, tls => $tls);
if (!(defined($status))) {
print "ERROR: XMPP connection failed.\n";
print " ($!)\n";
exit(0);
}
# Change hostname
my $sid = $Con->{SESSION}->{id};
$Con->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;
# Authenticate
my @result = $Con->AuthSend(
username => $username, password => $password,
resource => $resource);
if ($result[0] ne "ok") {
print "ERROR: Authorization failed: $result[0] - $result[1]\n";
exit(0);
}
else
{
print "Logged in Sucessfull!\nInvisible Users:\n";
}
$Con->PresenceSend(show=>"Available");
sub presence_ch
{
my $p=0;
my $x;
my $presence = pop;
my $from = $presence->GetFrom();
$from =~ s/([a-zA-Z@.]*)\/(.*)/$1/;
if($presence->GetType() eq "unavailable")
{
if (exists $online{$from})
{
delete($online{$from});
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
print $from."\n";
}
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
}
}
my $currtime;
while(1)
{
$currtime=time;
if($currtime-$sttime>10)
{last;}
my $res=$Con->Process(1);
if(!(defined($res))){ last;}}
XMPP protocol needs SSL encryption.So you need to install the perl modules for it.So before trying out the code make sure u have the following modules:
Followed by
for each of the module listed above
Also you need to install the package send-xmpp and it's dependecies
Run the program by running it as
The Chat Client should know who all are really online at any given time.This is because even when the person is invisible he/she should have a buddy list showing online users.
Ah!! Guess you did'nt understand a word till now.Let me try making it simpler.
Let's assume two users A and B are online now.Both A and B are Available (ie the chat client shows them online).Both A and B has a list of online users in his chat client(eg:google talk,gmail inbox chat,pidgin). Now this online users need to be kept constantly updated. This is done by the XMPP protocol(this is the protocol used by google for it's chat).Now even if B is invisible still it needs to keep it's online users list updated as it needs to show B the online users.
So whenever B logs into his account it initially sends a presence notification to all the users in it's contacts list saying that B is online as "Please show me online in our online user list".
All online users respond back with their online status and status message.
This is where the invisible people shows up.The chat server replies back with their status. The only difference in them is that they respond with their status as "Unavailable".
So my aim was to find out all users that respond back to me with Unavailable status and display them.
Ok enough of explanation of how it works let's see the code
#!/bin/perl
use strict;
use Net::XMPP;
my $sttime=time;
print "Username:$ARGV[0]\n";
my $username = "$ARGV[0]";
my $password = "$ARGV[1]";
my $resource = "SNIFFER";
my $hostname = 'talk.google.com';
my $port = 5222;
my $componentname = 'gmail.com';
my $Contype = 'tcpip';
my $tls = 1;
my %online;
my $Con = new Net::XMPP::Client();
$Con->SetCallBacks(presence=>\&presence_ch);
my $status = $Con->Connect(
hostname => $hostname, port => $port,
componentname => $componentname,
connectiontype => $Contype, tls => $tls);
if (!(defined($status))) {
print "ERROR: XMPP connection failed.\n";
print " ($!)\n";
exit(0);
}
# Change hostname
my $sid = $Con->{SESSION}->{id};
$Con->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;
# Authenticate
my @result = $Con->AuthSend(
username => $username, password => $password,
resource => $resource);
if ($result[0] ne "ok") {
print "ERROR: Authorization failed: $result[0] - $result[1]\n";
exit(0);
}
else
{
print "Logged in Sucessfull!\nInvisible Users:\n";
}
$Con->PresenceSend(show=>"Available");
sub presence_ch
{
my $p=0;
my $x;
my $presence = pop;
my $from = $presence->GetFrom();
$from =~ s/([a-zA-Z@.]*)\/(.*)/$1/;
if($presence->GetType() eq "unavailable")
{
if (exists $online{$from})
{
delete($online{$from});
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
print $from."\n";
}
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
}
}
my $currtime;
while(1)
{
$currtime=time;
if($currtime-$sttime>10)
{last;}
my $res=$Con->Process(1);
if(!(defined($res))){ last;}}
XMPP protocol needs SSL encryption.So you need to install the perl modules for it.So before trying out the code make sure u have the following modules:
- IO ::Socket ::SSL (>=0.81)
- XML ::Stream
- Net ::XMPP
- Authen ::SASL
sudo perl -MCPAN -e 'shell'
Followed by
install <module name>
for each of the module listed above
Also you need to install the package send-xmpp and it's dependecies
sudo apt-get install send-xmpp
Run the program by running it as
perl invi.pl <username> <password>
I have also made a online version of this script you can use to find invisible users the link is http://sriunplugged.blogspot.com/2008/11/online-version-of-perl-invisible-finder.html
Worked?? Did'nt work?? Comment me
Sunday, September 7, 2008
Automatic Command Archive
The default command storing size of ubuntu is 500 commands. It stores the commands in home folder in the file ".bash_history" .
The problem is 500 commands is too short of a size.
One method is to increase the command size to a large value by changing the $HISTFILESIZE variable using the following command
But this will last only till that terminal is closed.
Do make tat permanent or rather make that command execute every time u open a terminal we can put that command in .bashrc file in the home folder itself
The commands in this folder will be executed each time you open a terminal. So adding that command is one way to solve tat problem.
Or there is another way. Make a script tat will automatically archive the old commands to a file and compress it and save if it bigger than a specified size. That's a better method i feel.
Also i try to remove the repeated commands and store only unique ones there by not wasting space storing copies. This is a better method i feel than making it accumulate in the .bashrc.
So let's see how to do it.
File name:logarchive
echo "Ran at:"$(date) >>/home/$1/logs/commandrotate
echo "Size of History: "$(cat /home/$1/.bash_history|wc -l) >>/home/rsrijith/logs/commandrotate
if [ $(cat /home/$1/.bash_history|wc -l) -gt 400 ]
then
echo "Archived" >>/home/rsrijith/logs/commandrotate
cat -n /home/$1/.bash_history|sort -ru -k2|sort -n -k1|sed 's/[ ]*[0-9]*\t//' > /home/$1/.bash_history
cat /home/$1/.bash_history >>/home/$1/history/cmd_history
touch /home/$1/history/temp
cat -n /home/$1/history/cmd_history|sort -ru -k2|sort -n -k1|sed 's/[ ]*[0-9]*\t//' >/home/$1/history/cmd_history
tail -100 /home/$1/.bash_history >/home/$1/history/temp
cat /home/$1/history/temp >/home/$1/.bash_history
rm /home/$1/history/temp
fi
logrotate /home/$1/history/logrot.conf
if [ -e /home/$1/history/cmd_history.1 ]
then
gunzip "/home/$1/history/cmd_archive.gz"
cat /home/$1/history/cmd_history.1 >>/home/$1/history/cmd_archive
gzip -f "/home/$1/history/cmd_archive"
rm /home/$1/history/cmd_history.1
rm /home/$1/history/cmd_archive
fi
This script also reduces the current .bashrc file to only unique entry.Although there is a command (or rather environment variable) to store only unique values. But that only keeps the first entry in the file.So only the initial entry stays. I usually use the recently used commands using the up arrow in bash. So I need to maintain the order in which I have typed the command too. That's why I have used cat -n to get the order and have used it to order it in the end.
I have made the script run when the commands exceeds 400.
Once the cmd_history file goes over 1MB ,I try to compress it and store in as an archive. This is why i have used logrotate file
File name:logrot.conf
/home/rsrijith/history/cmd_history {
missingok
size 1M
rotate 1
}
Now we need to run it every 30mins or 1hr according to how much you use the commands.I have used 30mins just in case.So we use crontab (A scheduler in Linux).The crontab file is /etc/crontab.We can edit it using the command.
As we need to run it as root.Run the command as root.
So the crontab entry is as
*/30 * * * * root /home/rsrijith/history/logarchive rsrijith 2>>/home/rsrijith/logs/commandrotate
The problem is 500 commands is too short of a size.
One method is to increase the command size to a large value by changing the $HISTFILESIZE variable using the following command
export HISTFILESIZE=1000
But this will last only till that terminal is closed.
Do make tat permanent or rather make that command execute every time u open a terminal we can put that command in .bashrc file in the home folder itself
The commands in this folder will be executed each time you open a terminal. So adding that command is one way to solve tat problem.
Or there is another way. Make a script tat will automatically archive the old commands to a file and compress it and save if it bigger than a specified size. That's a better method i feel.
Also i try to remove the repeated commands and store only unique ones there by not wasting space storing copies. This is a better method i feel than making it accumulate in the .bashrc.
So let's see how to do it.
File name:logarchive
echo "Ran at:"$(date) >>/home/$1/logs/commandrotate
echo "Size of History: "$(cat /home/$1/.bash_history|wc -l) >>/home/rsrijith/logs/commandrotate
if [ $(cat /home/$1/.bash_history|wc -l) -gt 400 ]
then
echo "Archived" >>/home/rsrijith/logs/commandrotate
cat -n /home/$1/.bash_history|sort -ru -k2|sort -n -k1|sed 's/[ ]*[0-9]*\t//' > /home/$1/.bash_history
cat /home/$1/.bash_history >>/home/$1/history/cmd_history
touch /home/$1/history/temp
cat -n /home/$1/history/cmd_history|sort -ru -k2|sort -n -k1|sed 's/[ ]*[0-9]*\t//' >/home/$1/history/cmd_history
tail -100 /home/$1/.bash_history >/home/$1/history/temp
cat /home/$1/history/temp >/home/$1/.bash_history
rm /home/$1/history/temp
fi
logrotate /home/$1/history/logrot.conf
if [ -e /home/$1/history/cmd_history.1 ]
then
gunzip "/home/$1/history/cmd_archive.gz"
cat /home/$1/history/cmd_history.1 >>/home/$1/history/cmd_archive
gzip -f "/home/$1/history/cmd_archive"
rm /home/$1/history/cmd_history.1
rm /home/$1/history/cmd_archive
fi
I have made the script run when the commands exceeds 400.
Once the cmd_history file goes over 1MB ,I try to compress it and store in as an archive. This is why i have used logrotate file
File name:logrot.conf
/home/rsrijith/history/cmd_history {
missingok
size 1M
rotate 1
}
Now we need to run it every 30mins or 1hr according to how much you use the commands.I have used 30mins just in case.So we use crontab (A scheduler in Linux).The crontab file is /etc/crontab.We can edit it using the command.
crontab -e
As we need to run it as root.Run the command as root.
So the crontab entry is as
*/30 * * * * root /home/rsrijith/history/logarchive rsrijith 2>>/home/rsrijith/logs/commandrotate
Saturday, September 6, 2008
"Send To" in Linux
It's been a common practice among the windows users to right click and search for "Send To" option when a file needs to copied to the USB or any other Drive.
Why spare me, even i used to do this while using windows, when to my astonishment i found that there exists no such option in the default window ("Nautilus") in Ubuntu. So i thought of making one for my convenience.
Nautilus supports user scripts inside it. This can be easily embedded into the manager by inserting it into the folder ~/.gnome2/nautilus-scripts/ folder where ~ stands for the shortcut for home folder.
I used zenity ( a in build gnome dialog box) to get the radio box for selecting the drive to copy to.
The Send to function looks like this



The Code :
Why spare me, even i used to do this while using windows, when to my astonishment i found that there exists no such option in the default window ("Nautilus") in Ubuntu. So i thought of making one for my convenience.
Nautilus supports user scripts inside it. This can be easily embedded into the manager by inserting it into the folder ~/.gnome2/nautilus-scripts/ folder where ~ stands for the shortcut for home folder.
I used zenity ( a in build gnome dialog box) to get the radio box for selecting the drive to copy to.
The Send to function looks like this



The Code :
#!/bin/bash
destination='Choose Destination'
title_destination='Send files to:'
copy='Copying'
title_copy='Please wait...'
success='Files successfully copied'
title_success='Success'
errors='Something went wrong'
title_errors='Error'
no_writable='Destination is either not existant or writable'
title_no_writable='Error'
vd=$(ls -tm /media/sed 's/cdrom[0-9]\?[,]\?[ ]\?//g')
#options=${vd//, / FALSE /media/}
IFS=$'\t\n'
options=$(echo $vdsed 's_[ ]\?\([^,]*\),_\/media\/\1\tFALSE\t_g'sed 's_\(.*\)\tFALSE\t_\1_g');
destinazione=$(zenity --list --title "$title_destination" --text "$destination" --radiolist --column " " --column "Device" TRUE $options);
if [[ "$destinazione" = "" ]]; then
exit
fi
if [[ -w $destinazione ]]; then
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$(echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS)
destinazione=$(echo $destinazione)
cp -R "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" "$destinazione" zenity --progress --pulsate --auto-close --title="$title_copy" --text="$copy"
if (( $? == 0 )); then
zenity --info --text="$success" --title "$title_success";
else zenity --info --text="$errors" --title "$title_errors";
fi
else zenity --info --text="$no_writable" --title "$title_no_writable";
fi
destination='Choose Destination'
title_destination='Send files to:'
copy='Copying'
title_copy='Please wait...'
success='Files successfully copied'
title_success='Success'
errors='Something went wrong'
title_errors='Error'
no_writable='Destination is either not existant or writable'
title_no_writable='Error'
vd=$(ls -tm /media/sed 's/cdrom[0-9]\?[,]\?[ ]\?//g')
#options=${vd//, / FALSE /media/}
IFS=$'\t\n'
options=$(echo $vdsed 's_[ ]\?\([^,]*\),_\/media\/\1\tFALSE\t_g'sed 's_\(.*\)\tFALSE\t_\1_g');
destinazione=$(zenity --list --title "$title_destination" --text "$destination" --radiolist --column " " --column "Device" TRUE $options);
if [[ "$destinazione" = "" ]]; then
exit
fi
if [[ -w $destinazione ]]; then
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$(echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS)
destinazione=$(echo $destinazione)
cp -R "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" "$destinazione" zenity --progress --pulsate --auto-close --title="$title_copy" --text="$copy"
if (( $? == 0 )); then
zenity --info --text="$success" --title "$title_success";
else zenity --info --text="$errors" --title "$title_errors";
fi
else zenity --info --text="$no_writable" --title "$title_no_writable";
fi
Subscribe to:
Posts (Atom)

.png)
