Nothing To Lose

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

Archive for the ‘Linux’

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.

Sony Ericsson W350i on Linux (Mandriva 2009.1)

January 22, 2010 By: Dexter Category: Linux

Last year i took this phone because it could be used under Linux, i.e the phone memory card was accessible easily.

When I was using OpenSuse 10.2 (kernel version 2.6.18.2-34), when I used to connect the phone,(while the phone was on, the phone rebooted and asked an option to use it for ‘file transfer’ or ‘phone mode’, selecting file transfer), it was detected as sda1 and could be mounted, (it used to get mounted automatically).

Later when I tried to connect it on Mandriva 2009.1 (kernel  2.6.29.1)  using the above procedure, it would not get detected as mass storage device and the kernel kept trying to use it as a modem.

Finally i got a solution how to get it working in i.e get it detected as mass storage device.

First switch off the phone

connect the cable from the phone to computer.

Now the phone switches on automatically and will be automatically selected for flle transfer. Depending upon your system either it will get mounted automatically or you can mount it manually.

this is the o/p of ‘dmesg’

usb 2-5: new full speed USB device using ohci_hcd and address 4
usb 2-5: New USB device found, idVendor=0fce, idProduct=e0d0
usb 2-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-5: Product: Memory Stick
usb 2-5: Manufacturer: Sony Ericsson
usb 2-5: SerialNumber: 3558650274248670
usb 2-5: configuration #1 chosen from 1 choice
scsi9 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
scsi 9:0:0:0: Direct-Access     Sony Eri Memory Stick     0000 PQ: 0 ANSI: 0
sd 9:0:0:0: [sdb] 7852032 512-byte hardware sectors: (4.02 GB/3.74 GiB)
sd 9:0:0:0: [sdb] Test WP failed, assume Write Enabled
sd 9:0:0:0: [sdb] Assuming drive cache: write through
sd 9:0:0:0: [sdb] 7852032 512-byte hardware sectors: (4.02 GB/3.74 GiB)
sd 9:0:0:0: [sdb] Test WP failed, assume Write Enabled
sd 9:0:0:0: [sdb] Assuming drive cache: write through
sdb: sdb1
sd 9:0:0:0: [sdb] Attached SCSI removable disk
sd 9:0:0:0: Attached scsi generic sg2 type 0
usb-storage: device scan complete

Hope this is helpful if you are using the same on Linux.

Shifting to Window Maker

January 15, 2010 By: Dexter Category: Foss, Linux

The X File Explorer

The X File Explorer

If you are one of those, like me, slowly getting frustrated of too much of eye candy or unnecessary graphics, zip

zap zoom effects and want to get aways from it, window maker can be for you.
Window make will give four desktops, and very less icons on your desktop.

Now if you have become use to KDE you might want certain stuff to get you tuned to get started with window maker.

aterm

aterm

First thing that you need to do is get window makers menu. This is available on right click of screen. Please note that the menu will not just disappear off the screen, click on the upper right corner a cross will appear, click on it again.

Usually this menu is not very useful right now, we will see how to modify and get it according to your need later on in some other post.

But the first thing we need to do is get the “Run command dialog” box to get it working with alt+f2 key. So that we can run what ever commands from the dialog box easily.

xchat IRC client

xchat IRC client

Download/install few other things which you may want for daily work.

1) xfe –  the X file explore. A very light weight file manager, good for the CCP, ie cut copy paste.

2) aterm — a nice terminal — yes we have to leave ‘konsole’ behind. Suggested by Zoyd –
here is a nice combination for:- aterm command “aterm -tr +sb -sh 80 -fg cyan -font -*-fixed-*-14-*-*-iso8859-1″

3) gkrellm with loads of plug-ins.
4) Wvdial to get on to net

gkrellm

gkrellm

5) few text editor.  (vi on aterm is nice)
6) pidgin for all in one messenger
7) xchat for irc.. for more adventurous ones irssi
8) Was wondering how to take screen-shots, found out that GIMP can do the same. Nice found, in any case used to open the screen-shots to do the same. (start gimp –> file –> create –> new screenshot )

One issue is to get the resolution changing on the fly. use the following command on aterm:
to query modes that are applicable.
xrandr -q
1280×800       60.0*    50.0
1024×768       60.0
800×600        60.0     56.0

the first one or the marked is the current running mode
to change to any other use
xrandr -s 1
will change to 1024×768
to revert back
xrandr -s 0
where
0 is first mode
1 is second mode
2 is the last mode

More later….