bookmark_borderGet system load using Python Script

I have written a simple python script that collect system load information and store in a XML file.

#!/usr/bin/env python

import os
import commands
import time
from time import gmtime, strftime

while 0 < 10:
 
 file_name = strftime("%Y_%m_%d_%H_%M", gmtime()) 

 data =  commands.getoutput("w | grep load")
 xml_data = ""+ data + ""
 
 print xml_data
 
 
 if os.path.isfile(file_name + ".xml"):
  x=0
 else:

  f_prev=open(file_name + ".xml", 'a')
  f_prev.write("")
  f_prev.close

  f=open(file_name + ".xml", 'w')
  f.write("nn")
  f.close()

 
 f=open(file_name + ".xml", 'a')

 f.write(xml_data+"n")

 f.close()
 time.sleep(3)

We will get XML file like this.

<?xml version=’1.0′ encoding=’utf-8′?>
<data>
<load> 01:40:38 up 6:27, 3 users, load average: 0.07, 0.07, 0.03</load>
<load> 01:40:48 up 6:27, 3 users, load average: 0.06, 0.07, 0.03</load>
<load> 01:40:58 up 6:27, 3 users, load average: 0.05, 0.07, 0.03</load>
</data>

bookmark_borderBangla to Hex

Here is my Bangla to Hex converter using php and little ajax. Thanks to Mr. Jamil for giving me this idea.

index.php

<html>
<head>
<script type=”text/javascript” src=”ajax.js”> </script>
</head>
<body>
<div align=”center”><h1>Bangla HEX</h1></div>
<div align=”center”>salahuddin66.blogspot.com</div>
<br><br>
<form>
Input in UTF-8: <input type=”text” name=”input” onkeyup=”show(this.value)”>
</form>
<p>Hex: <span id=”txtHint”></span></p>
</body>
</html>


ajax.js

var xmlHttp

function show(str0)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (“Browser does not support HTTP Request”)
return
}
var url=”show.php”
url=url+”?q=”+str0
url=url+”&sid=”+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open(“GET”,url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
{
document.getElementById(“txtHint”).innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}

show.php

<?php

$q=$_GET[“q”];

unibin2hex($q);

function unibin2hex($u) {
$k = mb_convert_encoding($u, ‘UCS-2LE’, ‘UTF-8’);

$position = 0;

$run = strlen($u)/3;

for($i=0; $i

bookmark_borderSiemens-Sk65 udev script for GPRS

When I use GPRS some times my phone move to ttyUSB0 to ttyUSB1 and it disconnect me.

For the details doc: click here

I just add this in my udev.rules

KERNEL==”ttyUSB*”, BUS==”usb”, SYMLINK+=”siemens-sk65″

then in my wvdial.conf

Modem = /dev/siemens-sk65

example:

Jan 16 13:30:29 localhost kernel: usb 4-2: new full speed USB device using uhci_hcd and address 3
Jan 16 13:30:29 localhost kernel: usb 4-2: configuration #1 chosen from 1 choice
Jan 16 13:30:29 localhost kernel: pl2303 4-2:1.0: pl2303 converter detected
Jan 16 13:30:29 localhost kernel: usb 4-2: pl2303 converter now attached to ttyUSB0
Jan 16 13:30:52 localhost kernel: CSLIP: code copyright 1989 Regents of the University of California
Jan 16 13:30:52 localhost kernel: PPP generic driver version 2.4.2
Jan 16 13:30:52 localhost pppd[3339]: pppd 2.4.4 started by root, uid 0
Jan 16 13:30:53 localhost pppd[3339]: Using interface ppp0
Jan 16 13:30:53 localhost pppd[3339]: Connect: ppp0 /dev/ttyUSB0
Jan 16 13:30:55 localhost pppd[3339]: CHAP authentication succeeded
Jan 16 13:30:55 localhost pppd[3339]: CHAP authentication succeeded
Jan 16 13:30:55 localhost kernel: PPP BSD Compression module registered
Jan 16 13:30:55 localhost kernel: PPP Deflate Compression module registered
Jan 16 13:31:25 localhost pppd[3339]: IPCP: timeout sending Config-Requests
Jan 16 13:31:25 localhost pppd[3339]: Connection terminated.
Jan 16 13:31:25 localhost pppd[3339]: Exit.
Jan 16 13:31:33 localhost pppd[3388]: pppd 2.4.4 started by root, uid 0
Jan 16 13:31:33 localhost pppd[3388]: Using interface ppp0
Jan 16 13:31:33 localhost pppd[3388]: Connect: ppp0 /dev/ttyUSB0
Jan 16 13:31:36 localhost pppd[3388]: CHAP authentication succeeded
Jan 16 13:31:36 localhost pppd[3388]: CHAP authentication succeeded
Jan 16 13:31:39 localhost pppd[3388]: Cannot determine ethernet address for proxy ARP
Jan 16 13:31:39 localhost pppd[3388]: local IP address 10.87.9.211
Jan 16 13:31:39 localhost pppd[3388]: remote IP address 192.168.254.254
Jan 16 13:31:39 localhost pppd[3388]: primary DNS address 192.168.80.66
Jan 16 13:31:39 localhost pppd[3388]: secondary DNS address 202.134.13.3
Jan 16 14:07:29 localhost kernel: hub 4-0:1.0: port 2 disabled by hub (EMI?), re-enabling…
Jan 16 14:07:29 localhost kernel: usb 4-2: USB disconnect, address 3
Jan 16 14:07:29 localhost kernel: pl2303 4-2:1.0: device disconnected
Jan 16 14:07:29 localhost pppd[3388]: Modem hangup
Jan 16 14:07:29 localhost pppd[3388]: Connect time 35.9 minutes.
Jan 16 14:07:29 localhost pppd[3388]: Sent 283895 bytes, received 1000779 bytes.
Jan 16 14:07:29 localhost pppd[3388]: Connection terminated.
Jan 16 14:07:29 localhost pppd[3388]: Exit.
Jan 16 14:07:29 localhost kernel: usb 4-2: new full speed USB device using uhci_hcd and address 4
Jan 16 14:07:30 localhost kernel: usb 4-2: configuration #1 chosen from 1 choice
Jan 16 14:07:30 localhost kernel: pl2303 4-2:1.0: pl2303 converter detected
Jan 16 14:07:30 localhost kernel: usb 4-2: pl2303 converter now attached to ttyUSB1
Jan 16 14:07:30 localhost kernel: pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0
Jan 16 14:07:41 localhost pppd[3981]: pppd 2.4.4 started by root, uid 0
Jan 16 14:07:41 localhost pppd[3981]: Using interface ppp0
Jan 16 14:07:41 localhost pppd[3981]: Connect: ppp0 /dev/ttyUSB1
Jan 16 14:07:44 localhost pppd[3981]: CHAP authentication succeeded
Jan 16 14:07:44 localhost pppd[3981]: CHAP authentication succeeded
Jan 16 14:07:47 localhost pppd[3981]: Cannot determine ethernet address for proxy ARP
Jan 16 14:07:47 localhost pppd[3981]: local IP address 10.87.10.34
Jan 16 14:07:47 localhost pppd[3981]: remote IP address 192.168.254.254
Jan 16 14:07:47 localhost pppd[3981]: primary DNS address 192.168.80.66
Jan 16 14:07:47 localhost pppd[3981]: secondary DNS address 202.134.13.3

bookmark_borderallbn2unicode

i have started a project called allbn2unicode

#include stdio.h
#include stdlib.h
#include string.h
#include wchar.h
#include locale.h
#include langinfo.h

int main(int argc, char *argv[])
{
FILE *fp;
FILE *fp2;
wchar_t wr[80];
wchar_t *wca;
wchar_t hex,*hex2;
char str[80],*store;
int i,len;

/* set locale for bangla */
setlocale(LC_ALL, “bn_BD.UTF-8”);

store = str;

wca = wr;

if(argc!=3){
printf(“name n”);
exit(1);
}

if((fp = fopen(argv[1], “r”)) == NULL) {
printf(“Cannot open file.n”);
exit(1);
}

fgetws(wca, 100, fp);

/* if(fread(store,sizeof(store),1, fp) !=1) {
printf(“Cannot open file.n”);
exit(1);
} */

/* optional for asci file mbstowcs(wca, store,20);*/

fclose(fp);

if((fp2 = fopen(argv[2], “wb”)) == NULL) {
printf(“Cannot write file.n”);
}

if(wr[0]==0x0985)
{
hex=0x0987;
}
else

hex=0x0985;

fputws(wca,fp2);

fclose(fp2);

return 0;
}

bookmark_borderEDGE/GPRS in Linux

Today me (salahuddin66) and Lavluda successfully configured GPRS/EDGE in Linux.

Using wvdial

to check your mobile/modem as a modem
——————————-
#wvdialconf

it will generate /etc/wvdial.conf file for you.

Grameen Phone
For Grameen Phone your need to add

Init3 = AT+CGDCONT=1,”IP”,”gpinternet”

here is a sample of my /etc/wvdial.conf (Grameen Phone EDGE/GPRS)
————————————————————
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,”IP”,”gpinternet”
Modem Type = Analog Modem
ISDN = 0
Phone = *99***1#
Modem = /dev/ttyUSB0
Username = xyz
Password = xyz
Baud = 115200
———————————————————–
wvdialconf will generate the modem speed/Baud and /dev/xyz path according to your mobile phone

Aktel, Teletalk
here is a sample of my /etc/wvdial.conf
————————————————————
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
ISDN = 0
Phone = *99***1#
Modem = /dev/ttyUSB0
Username = xyz
Password = xyz
Baud = 115200
———————————————————–
wvdialconf will generate the modem speed/Baud and /dev/xyz path according to your mobile phone

Start
To start type wvdial in shell

Note:
If you have problem while generating wvdial.conf file in /etc/wvdial.conf then delete the old config file /etc/wvdial.conf and give wvdialconf to create a new configuraton file.

if you have any problem to find the /dev path for your mobile/modem, give

# tail -f /var/log/syslog

Then connect the phone/modem.
You can also use gnome-ppp or other ppp tools to connect.

Using gnome-ppp

Give phone number *99***1#

click on the detect. it will try to detect your phone/modem.
note: If it fails then give your /dev path manually. Search for you modem using #tail -f /var/log/syslog then connect the phone/modem.

it found my phone/modem in /dev/ttyUSB0

click Init Strings.
for Aktel, Teletalk and others (you do not need to change anything)

click Init Strings.
add Init3 only if you are using Grameen Phone EDGE/GPRS (only for GP)

after click connect

connected

details view

Note: If you face any problem using this as user. Run gnome-ppp as root
or check you are a member of dip group.

In Debian or Ubuntu based distro give #adduser your_user_name dip if your are not a member.

bookmark_borderall2theora

here is my all2theora script

(Thanks to my friend Zaher for fixing the Divx problem “-vf harddup”)
(based on Florian Schilhabel dvd2divx script Licence: GPL)

#!/usr/bin/perl

use Getopt::Long;

GetOptions( “help” => $help,
“i=s” => $input,
“divx=s” => $divx, );

if ($help) {
print “Welcome to the ALL2theora Helper Scriptn”;
print “n”;
print “this script encodes a all file to theoran”;
print “Usage:n”;
print “–help show this textn”;
print ” this will only be possible if you are rootn”;
print “–i Specify the Name of your Video filen”;
exit;
}

if ($input eq “”) {
print “No Input file selected – You must specify one with: –i filename.n”;
print “n”;
print “this script encodes a all file to theoran”;
print “Usage:n”;
print “–help show this textn”;
print ” this will only be possible if you are rootn”;
print “–i Specify the Name of your Video filen”;
exit;
}

if ($divx eq “on”) {

system (“mkfifo stream.yuv && chmod 777 stream.yuv && mencoder $input -ovc lavc -oac copy -o tmp.avi -lavcopts vcodec=mpeg1video:vbitrate=1200 -vf harddup -of mpeg && mplayer -vc dummy -vo null -ao pcm:file=stream.wav tmp.avi && encoder_example stream.wav stream.yuv > theora.ogg | mplayer -ao null -nosound -vo yuv4mpeg tmp.avi – 1>/dev/tty7 8>/dev/tty7 && rm stream.yuv && rm stream.wav && rm tmp.avi”);
exit;
}

if ($divx eq “off”) {
system (“mkfifo stream.yuv && chmod 777 stream.yuv && mplayer -vc dummy -vo null -ao pcm:file=stream.wav $input && encoder_example stream.wav stream.yuv > theora.ogg | mplayer -ao null -nosound -vo yuv4mpeg $input – 1>/dev/tty7 8>/dev/tty7 && rm stream.yuv && rm stream.wav”);
exit;
}

if ($divx eq “”) {
system (“mkfifo stream.yuv && chmod 777 stream.yuv && mplayer -vc dummy -vo null -ao pcm:file=stream.wav $input && encoder_example stream.wav stream.yuv > theora.ogg | mplayer -ao null -nosound -vo yuv4mpeg $input – 1>/dev/tty7 8>/dev/tty7 && rm stream.yuv && rm stream.wav”);
exit;
}

print “Video Filename: $inputn”;
print “working…n”;

exit;

Licence: GPL