Archive

Posts Tagged ‘Shell’

Huawei Modem not detecting in Ubuntu 10.04 Lucid – Fix

July 17th, 2010

I always like to do thinks in terminal, let me explain you in my way.  Use lsusb command to find if the modem is detected.

If detected use lsusb -v, to find the product id and vendor id of the modem.

In my case I am using Huawei EC168C – the vendor id is “12d1″ and product id is “1446″.

Open the terminal and follow the instructions

#sudo gedit /etc/udev/rules.d/15-huawei-115x.rules

Now paste the following content as follows and save.

SUBSYSTEM==”usb”,
SYSFS{idProduct}==”1446″,
SYSFS{idVendor}==”12d1″,
RUN+=”/lib/udev/modem-modeswitch –vendor 0x12d1 –product 0×1446 –type option-zerocd”

Save the file. Unplug and plug the modem. Now right click the network icon , goto Mobile Broadband and click Edit. Enter the phone and username.

In my case I am in Zantel network. The phone number is #777 and username is @zantel.com. Click the network icon again and click the detected modem to enjoy surfing.

Ubuntu , ,

A Shell Script to keep the Datanodes on MySQL NDB Clusters live and stable

January 7th, 2010

When i installed an ndb clusters, i found sometimes one of the datanodes, fails for some reason and they never start again untill it is manually done. So i wrote a shell script for the datanodes to check itself. The script checks in the ndbd process is running, if not its starts the process and writes a log. I added this shell script to the cron job to run the script every 10 minutes. Now the ndb clusters is perfectly stable for some months.

You may ask, 10 mins is too long. Does it mean, the database server will be down for 10 mins. Not beacuse there are more than 1 data node in the cluster, during this 10 mins other nodes will serve.

#!/bin/sh

logfile=/usr/local/mysql-cluster/restart.log

PID=`ps -eo ‘tty pid args’ | grep ‘ndbd’ | grep -v grep | tr -s ” | cut -f2 -d ”`

if [ -z "$PID" ]

then

message=`service ndbd start`

echo “`date` – NDBD started”>>$logfile

fi

Cron job that I added, (edit the file /etc/crontab and add the following line at the end)

*/10 * * * * root /path/to/the/script

This would keep the ndbclusters live for ever.

Linux, MySql NDB Clusters , ,

Fun with Forkbombs

May 25th, 2009

Try this small shell script in your terminal. To have more fun remote login to others desktops and try this command in the terminal.

:( ){ :| :& };:

This is a strange command in linux which crashes the system. Let me explain what exactly happens when this command is executed.

  • :( ) – Function header where : is the name of the function(Colon and two parenthesis)
  • { Opens the body of the function
  • A blank space is more important here, to have a good syntax
  • : recursive call to the same function(Colon)
  • |- pipes the out put of one function call to another
  • : which calls the function again (Colon)
  • & Forks, creates a child process and assigns the function call to it
  • } Closes the function definition
  • ; delimiter to end the function definition (Semicolon)
  • : actual call to the function(Colon)

So the above script calls recursively itself twice and forks it to a child process indefinitly. At a point the memory gets full and the system crashes. You can gaurd yourself from forkbombs by restricting the number of process that can be executed at a time. Have fun with fork bombs…

Bash, Linux ,

Some Frequently used Linux Commands

May 24th, 2009

Here are some of the frequently and very useful linux commands

Command Description
top A dynamic task list
ps -e To view the current snapshot of proccess at a time
kill <process-id> Kill a process by specifying its id. Process id can be found from the previous command
killall <process-name> Kill a process with its process name. The process name can be found using ps -e command
fdisk -l Displays the partion table and list of all the memory devices connected to the system
mount /dev/<device-name> /path/to/mountpoint Used to mount a external or internal memory device to the system. The device name can be found from the previous command.
mount -t ntfs-3g /dev/<device-name> /path/to/mountpoint -o force To force mount a memory device which uses ntfs file system
sudo nautilus To open the file browser in root mode. Normally when u open the file browser in ubuntu it will not be in root mode. Provided the currnet user is a sudoer
locate <file-name-pattern> Used to search or find files by their names. Normally the search is done based on a index database. It is good to update the database before searching to get recently created files.
updatedb Used to update the file index database
cat <filename> Display the contents of a file
cat <filename> | grep <pattern> The output of the first command is given as input to the next command using a pipe. Grep command display the lines that has pattern text

Use,   man<command-name> to get more details about all the above commands

Bash, Linux ,

Copying File across Between two systems in a Lan

July 9th, 2008

If in a Lan, Ping between two system to check the availability of the connection. If peer to peer, connect the lan cable. Assign the IP addresses for the two systems (Like 172.16.25.1 and 172.16.25.2 for both the systems, with subnet mask 255.255.255.0). That is the subnet addresses should be same for both the systems.

scp is the command that can be used for transfering files across the systems. Secure Copy(scp) uses Open SSH protocol for the file transfer. ftp can also be used for the file transfer. For using the scp command you must follow a rule. The rule is, the system you invoke this command should have the ssh client and the target system should have the ssh server(sshd). For copying the files from the source to the destination system, this command can be invoked in both source system or the destination system, but should follow the above rule.

The usage is the scp command is,

#scp username@<source-ip> :/path/to/the/source/file username@<destination-ip> :/path/to/the/destination/file

To copy a folder from the source system to the destination use the recursive the option,

#scp -r username@<source-ip> :/path/to/the/source/folder username@<destination-ip> :/path/to/the/destination/folder

The first user name is the user in the source system and the second username is the user in the destination system. The access privileges to the files or folder to copied or to be used as the destination folder depends on the user privileges used in the command.

Linux Networking , ,