Nothing To Lose

If you don’t have it, how can you lose it!
Subscribe

WordPress automatic upgrade Plugin

May 18, 2011 By: Dexter Category: Wordpress

If you are still stuck with one of those versions of WordPress which does not provide a facility of automatic upgrade you can try the WordPress automatic upgrade Plugin

In a few words it will do the required backup of the site, database get the latest WordPress for you and install it.

It worked for me! :)

Convert lines of text to HTML list item – using regex

March 21, 2011 By: Dexter Category: HTML, Regular Expressions, Web Development

Many a times I have to update pages where I need to display contents as HTML lists. The problems is the contents sent to me is in n number of lines of plain text.

Generally you will end up copy pasting <li> and </li> at the beginning and end of every line, for few lines it is ok, but what about if you have around 100 lines.

Well well well… if you knew regular expressions you life will be saved, here is what you do –

  • Copy paste all text in a text editor that supports find and replace with regular expression support.

This is line one
This is line two
This is line three
This is line four
This is line five
This is line ….
…………………….
…………………….
This is line fifty

  • open the replace dialogue box fill the following (make sure you have selected the regular-expression option for find)
    • find text : ^     (yup the carat symbol)
    • replace with : <li>
    • Hit replace all — all your lines should now be showing <li> in front of it.

<li>This is line one
<li>This is line two
<li>This is line three
<li>This is line four
<li>This is line five
<li>This is line ….
<li>…………………….
<li>…………………….
<li>This is line fifty

  • Open the replace dialogue box again and repeat the same steps again only:
    • find text now should be: $
    • replace with : </li>

<li>This is line one</li>
<li>This is line two</li>
<li>This is line three</li>
<li>This is line four</li>
<li>This is line five</li>
<li>This is line ….</li>
<li>…………………….</li>
<li>…………………….</li>
<li>This is line fifty</li>

  • Do forget to add unordered list or ordered list  tags <ul> or <ol> at the first line and </ul> or </ol> respectively as the last line to complete the HTML list.

<ul>

<li>This is line one</li>
<li>This is line two</li>
<li>This is line three</li>
<li>This is line four</li>
<li>This is line five</li>
<li>This is line ….</li>
<li>…………………….</li>
<li>…………………….</li>
<li>This is line fifty</li>

</ul>

And in three steps your complete text is now  a HTML list.

Adding Multiple Users With Random Password in Linux

March 19, 2011 By: Dexter Category: BASH, Linux, Linux Commands, Shell Scripting

Some or the other time you will come across a need to add multiple users to your Linux system, if it is 5 to 10 its ok, but what if you need to add a list of 100 or 200 users at a time.

What you need is a text file containing your username (Login ID) and random password separated by , (comma) stored in a file. I am calling this file uidpass.csv.

Loginid,Password
2001,k8jr9yic
2002,agiidmcc
2003,mp9cxmzj
2004,e3mjyxcb
2005,vlsvc3yc
2006,a9kelmhy
……………..
……………
2299,54wgh67b

Save this file as whatever name you want. Now what we need a is command to add users to the system. The useradd command in Linux lets you do that, intrestingly it also allows you to add the password with the option -p at the same time no need to use the passwd command. The only problem with the -p option is that it need the password to be provided in encrypted format.
Here the utility mkpasswd comes in handy. The mkpasswd command can take a string can return encrypted value for it that is required by the password option of useradd.

Here is the script which will read the file containing the userid,password

#!/bin/bash
for lines in `cat uidpass.csv`
do
userid=`echo $lines |cut -d’,’ -f1`
userpw=`echo $lines |cut -d’,’ -f2`
useradd -mc”New User $userid” -s /bin/bash  -p `mkpasswd $userpw`  $userid
done

So whats happening here lets see line by line

for lines in `cat uidpass.csv`
start the for loop read every line in uidpass.csv and put ever line one by one in lines variable for every iteration.

userid=`echo $lines |cut -d’,’ -f1`

cut the line in variable lines on the delimiter comma and store first field in variable userid

userpw=`echo $lines |cut -d’,’ -f2`

cut the line in variable lines on the delimiter comma and store second field in variable userpw

useradd -mc”New User $userid” -s /bin/bash  -p `mkpasswd $userpw`  $userid

Run the user add command for the username in userid and password in userpw, in the line itself the mkpasswd will encrypt the userpw and then give it to the option password option.

The loop will run for all the lines in your file.

hope this helps.

Using Sony W350i to Connect to internet under Linux

March 18, 2011 By: Dexter Category: Internet, Linux

Just for the heck of a backup net connection I tried out connecting to the internet through my Sony W350i phone.
Here are the steps how I got connected and what stuff I used for the same.

  • OS used Mandriva 2010 with Linux Kernel 2.6.31.
  • WvDial 1.60
  • Airtel GSM with GPRS Enabled

Connect you phone with the data cable provided to the computers USB.  The phone asks you to use Data Mode or Phone Mode, Select Phone mode.

Your device should get detected as ttyACM, just run the command dmesg after you have plugged in the phone. You should see some output like this

usb 1-1: new full speed USB device using ohci_hcd and address 13
usb 1-1: New USB device found, idVendor=0fce, idProduct=d0d0
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: Sony Ericsson W350
usb 1-1: Manufacturer: Sony Ericsson
usb 1-1: SerialNumber: 3558650274248670
usb 1-1: configuration #2 chosen from 1 choice
cdc_acm 1-1:2.1: ttyACM0: USB ACM device
cdc_wdm: probe of 1-1:2.5 failed with error -22

If you have an existing wvdial.conf file it is ok else you should run the wvdialconf utility to which will create a wvdial.conf for you by probing the existing phone modem.

Stupid Mode = On
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 = AT+CGDCONT=1,”IP”,”airtelgprs.com”
Modem Type = USB Modem
Phone = *99#
ISDN = 0
Username = ”
Password = ”
Modem = /dev/ttyACM0
Baud = 460800

Your wvdial should look similar to the one above except for the Init3 line missing or different.  Make sure it is there the “IP” and “airtelgprs.com” added this is need as the APN settings.

If you are using some other operator find out the APN and replace airtelgprs.com with the one they provide. (you can generally find this out in the phones internet connection settings)

The Phone number to dial is same for most of the GSM service providers, I doubt if you need to change it.

Your user name and password depends what ever your service provider gives you.

I left it blank, please keep single quotes without anything in it else wvdial complains that it could not find a user name and password.

next fire up the wvdial command and you should get connected to the net in few seconds.