[Linux] Vi editor basics


In everyday in our Linux life we may need to use vi editor. So do I. The main cause of this post is to know how simple vi editor is!

Installing Vi editor
sudo apt-get install vim

*it will also load color of you vi edior

Opening a file
vi filename

Creating text
Edit modes: These keys enter editing modes and type in the text
of your document. 

i     Insert before current cursor position
I     Insert at beginning of current line
a     Insert (append) after current cursor position
A     Append to end of line
r     Replace 1 character
R     Replace mode
<ESC> Terminate insertion or overwrite mode

Going to VISUAL mode:
If you want visual then from command mode just hit "v" 

v    it will allow to switch in visual mode

Deletion of text

x     Delete single character
dd    Delete current line and put in buffer
ndd   Delete n lines (n is a number) and put them in buffer
J     Attaches the next line to the end of the current line (deletes carriage return).

Undo:
u     Undo last command

cut and paste
yy    Yank current line into buffer
nyy   Yank n lines into buffer
p     Put the contents of the buffer after the current line
P     Put the contents of the buffer before the current line

cursor positioning
^d    Page down
^u    Page up
:n    Position cursor at line n
:$    Position cursor at end of file
^g    Display current line number
h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also work if your keyboard mappings are anywhere near sane.

string substitution

:n1,n2:s/string1/string2/[g]       Substitute string2 for string1 on lines
                                   n1 to n2. If g is included (meaning global),
                                   all instances of string1 on each line
                                   are substituted. If g is not included,
                                   only the first instance per matching line is
                                   substituted.

    ^ matches start of line
    . matches any single character
    $ matches end of line

These and other "special characters" (like the forward slash) can be "escaped" with \
i.e to match the string "/usr/STRIM100/SOFT" say "\/usr\/STRIM100\/SOFT" 

Examples:

:1,$:s/dog/cat/g                   Substitute 'cat' for 'dog', every instance
                                   for the entire file - lines 1 to $ (end of file)

:23,25:/frog/bird/                 Substitute 'bird' for 'frog' on lines
                                   23 through 25. Only the first instance
                                   on each line is substituted.

Saving and quitting and other "ex" commands

These commands are all prefixed by pressing colon (:) and then entered in the lower
left corner of the window. They are called "ex" commands because they are commands
of the ex text editor - the precursor line editor to the screen editor
vi.   You cannot enter an "ex" command when you are in an edit mode (typing text onto the screen)
Press <ESC> to exit from an editing mode.

:w                Write the current file.
:w new.file       Write the file to the name 'new.file'.
:w! existing.file Overwrite an existing file with the file currently being edited.
:wq               Write the file and quit.
:q                Quit.
:q!               Quit with no changes.

:e filename       Open the file 'filename' for editing.

:set number       Turns on line numbering
:set nonumber     Turns off line numbering

i think it will help someone!
:)
Advertisements

Unix/Linux Commands for everyday use

I have enlisted Unix/Linux commands for everyday use. Hope this list may also help someone.

dir navigation
cd – Go to previous directory
cd Go to $HOME directory
(cd dir && command) Go to dir, execute command and return to current dir
pushd . Put current dir on stack so you can popd back to it
file searching
alias l=’ls -l –color=auto’ quick dir listing
ls -lrt List files by date. See also newest and find_mm_yyyy
ls /usr/bin | pr -T9 -W$COLUMNS Print in 9 columns to width of terminal
find -name ‘*.[ch]’ | xargs grep -E ‘expr’ Search ‘expr’ in this dir and below. See also findrepo
find -type f -print0 | xargs -r0 grep -F ‘example’ Search all regular files for ‘example’ in this dir and below
find -maxdepth 1 -type f | xargs grep -F ‘example’ Search all regular files for ‘example’ in this dir
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done Process each item with multiple commands (in while loop)
find -type f ! -perm -444 Find files not readable by all (useful for web site)
find -type d ! -perm -111 Find dirs not accessible by all (useful for web site)
locate -r ‘file[^/]*\.txt’ Search cached index for names. This re is like glob *file*.txt
look reference Quickly search (sorted) dictionary for prefix
grep –color reference /usr/share/dict/words Highlight occurances of regular expression in dictionary
archives and compression
gpg -c file Encrypt file
gpg file.gpg Decrypt file
tar -c dir/ | bzip2 > dir.tar.bz2 Make compressed archive of dir/
bzip2 -dc dir.tar.bz2 | tar -x Extract archive (use gzip instead of bzip2 for tar.gz files)
tar -c dir/ | gzip | gpg -c | ssh user@remote ‘dd of=dir.tar.gz.gpg’ Make encrypted archive of dir/ on remote machine
find dir/ -name ‘*.txt’ | tar -c –files-from=- | bzip2 > dir_txt.tar.bz2 Make archive of subset of dir/ and below
find dir/ -name ‘*.txt’ | xargs cp -a –target-directory=dir_txt/ –parents Make copy of subset of dir/ and below
( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p ) Copy (with permissions) copy/ dir to /where/to/ dir
( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p ) Copy (with permissions) contents of copy/ dir to /where/to/
( tar -c /dir/to/copy ) | ssh -C user@remote ‘cd /where/to/ && tar -x -p’ Copy (with permissions) copy/ dir to remote:/where/to/ dir
dd bs=1M if=/dev/sda | gzip | ssh user@remote ‘dd of=sda.gz’ Backup harddisk to remote machine
rsync (Network efficient file copier: Use the –dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file file Only get diffs. Do multiple times for troublesome downloads
rsync –bwlimit=1000 fromfile tofile Locally copy with rate limit. It’s like nice for I/O
rsync -az -e ssh –delete ~/public_html/ remote.com:’~/public_html’ Mirror web site (using compression and encryption)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/ Synchronize current directory with remote one
ssh (Secure SHell)
ssh $USER@$HOST command Run command on $HOST as $USER (default command=shell)
ssh -f -Y $USER@$HOSTNAME xeyes Run GUI command on $HOSTNAME as $USER
scp -p -r $USER@$HOST: file dir/ Copy with permissions to $USER’s home directory on $HOST
scp -c arcfour $USER@$LANHOST: bigfile Use faster crypto for local LAN. This might saturate GigE
ssh -g -L 8080:localhost:80 root@$HOST Forward connections to $HOSTNAME:8080 out to $HOST:80
ssh -R 1434:imap:143 root@$HOST Forward connections from $HOST:1434 in to imap:143
ssh-copy-id $USER@$HOST Install public key for $USER@$HOST for password-less log in
wget (multi purpose download tool)
(cd dir/ && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html) Store local browsable version of a page to the current dir
wget -c http://www.example.com/large.file Continue downloading a partially downloaded file
wget -r -nd -np -l1 -A ‘*.jpg’ http://www.example.com/dir/ Download a set of files to the current directory
wget ftp://remote/file[1-9].iso/ FTP supports globbing directly
wget -q -O- http://www.pixelbeat.org/timeline.html | grep ‘a href’ | head Process output directly
echo ‘wget url’ | at 01:00 Download url at 1AM to current dir
wget –limit-rate=20k url Do a low priority download (limit to 20KB/s in this case)
wget -nv –spider –force-html -i bookmarks.html Check links in a file
wget –mirror http://www.example.com/ Efficiently update a local copy of a site (handy from cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
ethtool eth0 Show status of ethernet interface eth0
ethtool –change eth0 autoneg off speed 100 duplex full Manually set ethernet interface speed
iwconfig eth1 Show status of wireless interface eth1
iwconfig eth1 rate 1Mb/s fixed Manually set wireless interface speed
iwlist scan List wireless networks in range
ip link show List network interfaces
ip link set dev eth0 name wan Rename interface eth0 to wan
ip link set dev eth0 up Bring interface eth0 up (or down)
ip addr show List addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0 Add (or del) ip and mask (255.255.255.0)
ip route show List routing table
ip route add default via 1.2.3.254 Set default gateway to 1.2.3.254
host pixelbeat.org Lookup DNS ip address for name or vice versa
hostname -i Lookup local ip address (equivalent to host `hostname`)
whois pixelbeat.org Lookup whois info for hostname or ip address
netstat -tupl List internet services on a system
netstat -tup List active connections to/from system
windows networking (Note samba is the package that provides all this windows specific networking support)
smbtree Find windows machines. See also findsmb
nmblookup -A 1.2.3.4 Find the windows (netbios) name associated with ip address
smbclient -L windows_box List shares on windows machine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/share Mount a windows share
echo ‘message’ | smbclient -M windows_box Send popup to windows machine (off by default in XP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing with the -i option)
sed ‘s/string1/string2/g’ Replace string1 with string2
sed ‘s/\(.*\)1/\12/g’ Modify anystring1 to anystring2
sed ‘/ *#/d; /^ *$/d’ Remove comments and blank lines
sed ‘:a; /\\$/N; s/\\\n//; ta’ Concatenate lines with trailing \
sed ‘s/[ \t]*$//’ Remove trailing spaces from lines
sed ‘s/\([`”$\]\)/\\\1/g’ Escape shell metacharacters active within double quotes
seq 10 | sed “s/^/      /; s/ *\(.\{7,\}\)/\1/” Right align numbers
sed -n ‘1000{p;q}’ Print 1000th line
sed -n ‘10,20p;20q Print lines 10 to 20
sed -n ‘s/.*<title>\(.*\)<\/title>.*/\1/ip;T;q Extract title from HTML web page
sed -i 42d ~/.ssh/known_hosts Delete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses
echo ‘Test’ | tr ‘[:lower:]’ ‘[:upper:]’ Case conversion
tr -dc ‘[:print:]’ < /dev/urandom Filter non printable characters
tr -s ‘[:blank:]’ ‘\t’ </proc/diskstats | cut -f4 cut fields separated by blanks
history | wc -l Count lines
set operations (Note you can export LANG=C for speed. Also these assume no duplicate lines within a file)
sort file1 file2 | uniq Union of unsorted files
sort file1 file2 | uniq -d Intersection of unsorted files
sort file1 file1 file2 | uniq -u Difference of unsorted files
sort file1 file2 | uniq -u Symmetric Difference of unsorted files
join -t” -a1 -a2 file1 file2 Union of sorted files
join -t” file1 file2 Intersection of sorted files
join -t” -v2 file1 file2 Difference of sorted files
join -t” -v1 -v2 file1 file2 Symmetric Difference of sorted files
math
echo ‘(1 + sqrt(5))/2’ | bc -l Quick math (Calculate φ). See also bc
seq -f ‘4/%g’ 1 2 99999 | paste -sd-+ | bc -l Calculate π the unix way
echo ‘pad=20; min=64; (100*10^6)/((pad+min)*8)’ | bc More complex (int) e.g. This shows max FastE packet rate
echo ‘pad=20; min=64; print (100E6)/((pad+min)*8)’ | python Python handles scientific notation
echo ‘pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)’ | gnuplot -persist Plot FastE packet rate vs packet size
echo ‘obase=16; ibase=10; 64206’ | bc Base conversion (decimal to hexadecimal)
echo $((0x2dec)) Base conversion (hex to dec) ((shell arithmetic expansion))
units -t ‘100m/9.58s‘ ‘miles/hour’ Unit conversion (metric to imperial)
units -t ‘500GB’ ‘GiB’ Unit conversion (SI to IEC prefixes)
units -t ‘1 googol’ Definition lookup
seq 100 | (tr ‘\n’ +; echo 0) | bc Add a column of numbers. See also add and funcpy
calendar
cal -3 Display a calendar
cal 9 1752 Display a calendar for a particular month year
date -d fri What date is it this friday. See also day
[ $(date -d ’12:00 +1 day’ +%d) = ’01’ ] || exit exit a script unless it’s the last day of the month
date –date=’25 Dec’ +%A What day does xmas fall on, this year
date –date=’@2147483647′ Convert seconds since the epoch (1970-01-01 UTC) to date
TZ=’America/Los_Angeles’ date What time is it on west coast of US (use tzselect to find TZ)
date –date=’TZ=”America/Los_Angeles” 09:00 next Fri’ What’s the local time for 9AM next Friday on west coast US
locales
printf “%’d\n” 1234 Print number with thousands grouping appropriate to locale
BLOCK_SIZE=\’1 ls -l Use locale thousands grouping in ls. See also l
echo “I live in `locale territory`” Extract info from locale database
LANG=en_IE.utf8 locale int_prefix Lookup locale info for specific country. See also ccodes
locale -kc $(locale | sed -n ‘s/\(LC_.\{4,\}\)=.*/\1/p’) | less List fields available in locale database
recode (Obsoletes iconv, dos2unix, unix2dos)
recode -l | less Show available conversions (aliases on each line)
recode windows-1252.. file_to_change.txt Windows “ansi” to local charset (auto does CRLF conversion)
recode utf-8/CRLF.. file_to_change.txt Windows utf8 to local charset
recode iso-8859-15..utf8 file_to_change.txt Latin9 (western europe) to utf8
recode ../b64 < file.txt > file.b64 Base64 encode
recode /qp.. < file.qp > file.txt Quoted printable decode
recode ..HTML < file.txt > file.html Text to HTML
recode -lf windows-1252 | grep euro Lookup table of characters
echo -n 0x80 | recode latin-9/x1..dump Show what a code represents in latin-9 charmap
echo -n 0x20AC | recode ucs-2/x2..latin-9/x Show latin-9 encoding
echo -n 0x20AC | recode ucs-2/x2..utf-8/x Show utf-8 encoding
CDs
gzip < /dev/cdrom > cdrom.iso.gz Save copy of data cdrom
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gz Create cdrom image from contents of dir
mount -o loop cdrom.iso /mnt/dir Mount the cdrom image at /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fast Clear a CDRW
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom – Burn cdrom image (use dev=ATAPI -scanbus to confirm dev)
cdparanoia -B Rip audio tracks from CD to wav files in current dir
cdrecord -v dev=/dev/cdrom -audio -pad *.wav Make audio CD from all wavs in current dir (see also cdrdao)
oggenc –tracknum=’track’ track.cdda.wav -o ‘track.ogg’ Make ogg file from wav file
disk space (See also FSlint)
ls -lSr Show files by size, biggest last
du -s * | sort -k1,1rn | head Show top disk users in current dir. See also dutop
du -hs /home/* | sort -k1,1h Sort paths by easy to interpret disk usage
df -h Show free space on mounted filesystems
df -i Show free inodes on mounted filesystems
fdisk -l Show disks partitions sizes and types (run as root)
rpm -q -a –qf ‘%10{SIZE}\t%{NAME}\n’ | sort -k1,1n List all packages by installed size (Bytes) on rpm distros
dpkg-query -W -f=’${Installed-Size;10}\t${Package}\n’ | sort -k1,1n List all packages by installed size (KBytes) on deb distros
dd bs=1 seek=2TB if=/dev/null of=ext3.test Create a large test file (taking no space). See also truncate
> file truncate data of file or create an empty file
monitoring/debugging
tail -f /var/log/messages Monitor messages in a log file
strace -c ls >/dev/null Summarise/profile system calls made by command
strace -f -e open ls >/dev/null List system calls made by command
strace -f -e trace=write -e write=1,2 ls >/dev/null Monitor what’s written to stdout and stderr
ltrace -f -e getenv ls >/dev/null List library calls made by command
lsof -p $$ List paths that process id has open
lsof ~ List processes that have specified path open
tcpdump not port 22 Show network traffic except ssh. See also tcpdump_not_me
ps -e -o pid,args –forest List processes in a hierarchy
ps -e -o pcpu,cpu,nice,state,cputime,args –sort pcpu | sed ‘/^ 0.0 /d’ List processes by % cpu usage
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS List processes by mem (KB) usage. See also ps_mem.py
ps -C firefox-bin -L -o pid,tid,pcpu,state List all threads for a particular process
ps -p 1,$$ -o etime= List elapsed wall time for particular process IDs
last reboot Show system reboot history
free -m Show amount of (remaining) RAM (-m displays in MB)
watch -n.1 ‘cat /proc/interrupts’ Watch changeable data continuously
udevadm monitor Monitor udev events to help configure rules
system information (see also sysinfo) (‘#’ means root access is required)
uname -a Show kernel version and system architecture
head -n1 /etc/issue Show name and version of distribution
cat /proc/partitions Show all partitions registered on the system
grep MemTotal /proc/meminfo Show RAM total seen by the system
grep “model name” /proc/cpuinfo Show CPU(s) info
lspci -tv Show PCI info
lsusb -tv Show USB info
mount | column -t List mounted filesystems on the system (and align output)
grep -F capacity: /proc/acpi/battery/BAT0/info Show state of cells in laptop battery
# dmidecode -q | less Display SMBIOS/DMI information
# smartctl -A /dev/sda | grep Power_On_Hours How long has this disk (system) been powered on in total
# hdparm -i /dev/sda Show info about disk sda
# hdparm -tT /dev/sda Do a read speed test on disk sda
# badblocks -s /dev/sda Test for unreadable blocks on disk sda


Listing some contents with examples: 

Listing directory contents: 

ls    list a directory
ls -l    list a directory in long ( detailed ) format

   for example:
$ ls -l
drwxr-xr-x    4 cliff    user        1024 Jun 18 09:40 WAITRON_EARNINGS
-rw-r--r--    1 cliff    user      767392 Jun  6 14:28 scanlib.tar.gz
^ ^  ^  ^     ^   ^       ^           ^      ^    ^      ^
| |  |  |     |   |       |           |      |    |      |
| |  |  |     | owner   group       size   date  time    name
| |  |  |     number of links to file or directory contents
| |  |  permissions for world
| |  permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no permission
type of file: - = normal file, d=directory, l = symbolic link, and others...

ls -a        List the current directory including hidden files. Hidden files start
             with "."
ls -ld *     List all the file and directory names in the current directory using
             long format. Without the "d" option, ls would list the contents
             of any sub-directory of the current. With the "d" option, ls
             just lists them like regular files. 

Changing file permissions and attributes 

chmod 755 file       Changes the permissions of file to be rwx for the owner, and rx for
                     the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)
chgrp user file      Makes file belong to the group user.
chown cliff file     Makes cliff the owner of file.
chown -R cliff dir   Makes cliff the owner of dir and everything in its directory tree. 

You must be the owner of the file/directory or be root before you can do any of these things. 

Viewing and editing files: 

cat filename      Dump a file to the screen in ascii.
more filename     Progressively dump a file to the screen: ENTER = one line down
                  SPACEBAR = page down  q=quit
less filename     Like more, but you can use Page-Up too. Not on all systems.
vi filename       Edit a file using the vi editor. All UNIX systems will have vi in some form.
emacs filename    Edit a file using the emacs editor. Not all systems will have emacs.
head filename     Show the first few lines of a file.
head -n  filename Show the first n lines of a file.
tail filename     Show the last few lines of a file.
tail -n filename  Show the last n lines of a file.

Environment variables 

You can teach your shell to remember things for later using environment variables.
For example under the bash shell:

export CASROOT=/usr/local/CAS3.0               Defines the variable CASROOT with the value
                                               /usr/local/CAS3.0.
export LD_LIBRARY_PATH=$CASROOT/Linux/lib      Defines the variable LD_LIBRARY_PATH with
                                               the value of CASROOT with /Linux/lib appended,
                                               or /usr/local/CAS3.0/Linux/lib 

By prefixing $ to the variable name, you can evaluate it in any command:

cd $CASROOT         Changes your present working directory to the value of CASROOT

echo $CASROOT       Prints out the value of CASROOT, or /usr/local/CAS3.0
printenv CASROOT    Does the same thing in bash and some other shells. 

Pipes: 

The pipe symbol "|" is used to direct the output of one command to the input
of another.

For example:

ls -l | more   This commands takes the output of the long format directory list command
               "ls -l" and pipes it through the more command (also known as a filter).
               In this case a very long list of files can be viewed a page at a time.

du -sc * | sort -n | tail
               The command "du -sc" lists the sizes of all files and directories in the
               current working directory. That is piped through "sort -n" which orders the
               output from smallest to largest size. Finally, that output is piped through "tail"
               which displays only the last few (which just happen to be the largest) results.
 

Naraio : a complete software bundle of Trac and SVN authentication including OpenLDAP

About Naraio :
Naraio is a free and open source product. It consists of Apache, OpenLDAP, MySql, PHP, Openssl, Perl, Trac, Subversion, Ruby, Python, PhpLDAPadmin and, PhpMyAdmin. It is easy, secure, small and flexible.

Where you can use ?
Naraio can be used as directory service(openldap), Project management(trac), Version control (subversion), web development, and database management (Mysql). Other open source products can be easily installed in Naraio.

Key features
Naraio is available for Linux operating system like Fedora, Redhat, Centos, Debian, Ubuntu and use for web development projects. Naraio comes with setup script for easy installation and backup. Naraio authenticates users with compiled openldap. Naraio is good product for lazy system administrator. Naraio installation/setup doesn’t take more than 5 mins as it is very difficult to install all components separately. It is easy to move installed Naraio from one system to another.

Naraio includes :

> OpenSSL
> Berkeley DB
> OPENLDAP
> zlib
> Apache
> Gettext
> Python
> Perl
> Ruby
> Swig
> Neon
> Docutils
> PySqlite
> cyrus-sasl
> libtool
> PHP
> Subversion
> Trac
> PythonLDAP
> Mysql
> PhpMyAdmin
> PhpLDAPadmin

Interested? Wanna Download?

Download Naraio

Who should use Naraio ?
If you are lazy system administrator you should give a try ….. 😛

[ubuntu] GrameenPhone’s Internet with Mobidata EDGE modem in ubuntu

Lot’s of UBUNTU users in Bangladesh are searching to configure Mobidata EDGE modem. Well, the most effective way to connect internet is wvdial. If it’s your lucky day then the following steps will work fine.

Step 1: First things first, make sure you are enable your repository from your software source.

Step 2: Now, in the terminal type

$ sudo wvdial

, If you are getting command not found that means you don’t have wvdialconf

For Ubuntu 9.10 (karmic koala) 4 files needed:

1. http://packages.ubuntu.com/karmic/i386/libwvstreams4.6-base/download
2. http://packages.ubuntu.com/karmic/i386/libwvstreams4.6-extras/download
3. http://packages.ubuntu.com/karmic/i386/libuniconf4.6/download
4. http://packages.ubuntu.com/karmic/i386/wvdial/download

All 4 files in .zip can be found (i386) into here

Update for Ubuntu 10.04
Although wvdial and dependencies are included into CD of 10.04 are NOT installed by default! Bug#400573
You do not need to download them, just use the .iso or LiveCD or LiveUSB following the procedure below:

1. right click ubuntu-10.04-desktop-i386.iso and ‘open with archive mounter’
(or mount LiveCD/LiveUSB)
2. right click on icon created (from 1) to ‘browse folder’
3. create a folder on Desktop (ex. named ‘wvdial’)
4. copy into that folder all 4 .deb files that exist into .iso/LiveCD/LiveUSB
… /pool/main/w/wvdial
and /pool/main/w/wvstreams
5. use System > Administration > Synaptic Package Manager
and then from menu File > Add downloaded packages > double click Desktop and then the folder you created at point #3, click open, follow instructions to
install

OR, you can got to step 5.

Step 3:If you can manage internet connection some how then go to terminal type

$ sudo apt-get install wvdialconf

Without installing PLEASE DON’T PROCEED.

Step 4: After installing wvdialconf you have a file name wvdial.conf in

/etc/wvdial.conf. Go to terminal type

$ sudo gedit /etc/wvdial.conf

. This will open the file with gEdit.

Step 5: Now copy and paste from below in /etc/wvdial.conf you are all most done!

[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 = 460800
New PPPD = yes

Step 5: You are done! Go to terminal and try again

$ sudo wvdial

. Hope you can find [connect] word!!

[NOTE:] make sure that your Mobidata EDGE modem found in /dev folder like /dev/ttyUSB0 or whatever! just put the name correctly in the modem section.

Now you can enjoy your GrameenPhone’s Internet with Mobidata EDGE modem in ubuntu all the time.

Enjoy 😉

[Tips] MP3 support, DVD playback in Ubuntu

Some times it is really disturbing after installed a new Ubuntu/Linux and cant play mp3 files. That’s why i need to make a note down here 😀

1. MP3 support, DVD playback, Java plugin, and Flash plugin

To install ubuntu-restricted-extras package. In terminal window, command is:

sudo apt-get install ubuntu-restricted-extras

For Kubuntu, command is :

sudo apt-get install kubuntu-restricted-extras

For Xubuntu, command is:

sudo apt-get install xubuntu-restricted-extras

2. Install w32codecs

This non-free multimedia codecs will be used for MPlayer and Xine. To install w32codecs, you can see also here.

3. Install CompizConfig Settings Manager

sudo apt-get install compizconfig-settings-manager

4. Install Opera 9.24

To use commercial repository for Ubuntu 7.10.

sudo gedit /etc/apt/sources.list

Add this line:

deb http://archive.canonical.com/ gutsy partner

After save file, run these commands:

sudo apt-get update
sudo apt-get install opera

5. Clean up Ubuntu

To clean up Ubuntu 7.10, run the following commands:

sudo apt-get autoclean
sudo apt-get clean

Or use:

sudo apt-get autoremove

Done!

[Apache] Loopback Interface Testing

Sometimes it’s really important to test multiple websites on localhost. How we can do that? Very easy! ;).. Yes we can use different port for each site. Some days ago i found one of the windows hosting server did this for their different users. So we can also be able to to it in apache..

What we need is to initialize the port for each site.. here is an example

We need to edit our httpd.conf file and paste these code in the suitable place

Listen 127.0.0.1:8000
Listen 127.0.0.1:1111
BindAddress 127.0.0.1

Port 1111
Port 8000

ServerName 127.0.0.1

NameVirtualHost *

<VirtualHost *:8000>
DocumentRoot “/home/username/test/example.org/htdocs”
<Directory “/home/username/test/example.org/htdocs”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:1111>
DocumentRoot “/home/username/test/example.com/htdocs/”
<Directory “/home/username/test/example.com/htdocs/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

done, now port 8000 is for our development and 1111 is for testing purpose

enjoy 😉

Ref: Security Tips for Server Configuration

[Linux] Crontab every 5 minutes

Well, if you are searching How to set a cron job? or want to schedules to run a cron job every 5 minutes. Then proceed reading.
Here, I will show how to schedule a cron and run that every five minutes to execute some desired results.

To edit the crontab i use the following command:

$ crontab -e

To list my currnet crontab

$ crontab -l

The following is the format entries in a crontab must be. Note all lines starting with # are ignored, comments.

So in terminal print ‘Hello’ every 5 minutes..


# MIN   HOUR   MDAY  MON  DOW   COMMAND 
   */5     *      *     *    *    echo 'Hello' 

MIN Minute 0-60
HOUR Hour [24-hour clock] 0-23
MDAY Day of Month 1-31
MON Month 1-12 OR jan,feb,mar,apr …
DOW Day of Week 0-6 OR
sun,mon,tue,wed,thu,fri,sat
COMMAND Command to be run Any valid command-line

Examples

Here are a few examples, to see what some entries look like.

#Run command at 7:00am each weekday [mon-fri]
00 07 * * 1-5 mail_pager.script ‘Wake Up’

#Run command on 1st of each month, at 5:30pm
30 17 1 * * pay_rent.script

#Run command at 8:00am,10:00am and 2:00pm every day
00 8,10,14 * * * do_something.script

#Run command every 5 minutes during market hours
*/5 6-13 * * mon-fri get_stock_quote.script

#Run command every 3-hours while awake
0 7-23/3 * * * drink_water.script

Special Characters in Crontab

You can use an

asterisk

in any category to mean for every item, such as every day or every month.

You can use commas in any category to specify multiple values. For example: mon,wed,fri

You can use dashes to specify ranges. For example: mon-fri, or 9-17

You can use forward slash to specify a repeating range. For example: */5 for every five minutes, hours, days
Special Entries

There are several special entries, some which are just shortcuts, that you can use instead of specifying the full cron entry.

The most useful of these is probably @reboot which allows you to run a command each time the computer gets reboot. This could be useful if you want to start up a server or daemon under a particular user, or if you do not have access to the rc.d/init.d files.

Example Usage:

# restart freevo servers
@reboot freevo webserver start
@reboot freevo recordserver start

The complete list:

Entry Description Equivalent To
@reboot Run once, at startup. None
@yearly Run once a year 0 0 1 1 *
@annually (same as @yearly) 0 0 1 1 *
@monthly Run once a month 0 0 1 * *
@weekly Run once a week 0 0 * * 0
@daily Run once a day 0 0 * * *
@midnight (same as @daily) 0 0 * * *
@hourly Run once an hour 0 * * * *

Miscelleanous Issues

Script Output
If there is any output from your script or command it will be sent to that user’s e-mail account, on that box. Using the default mailer which must be setup properly.

You can set the variable MAILTO in the crontab to specify a separate e-mail address to use. For example:
MAILTO=”admin@mydomain.com”

Redirect Output to /dev/null
You can redirect the output from a cron script to /dev/null which just throws it away. By redirecting to /dev/null you will not receive anything from the script, even if it is throwing errors.
* * * * * /script/every_minute.pl > /dev/null 2>&1

Missed Schedule Time
Cron does not run a command if it was missed. Your computer must be running for cron to run the job at the time it is scheduled. For example, if you have a 1:00am scheduled job and your computer was off at that time, it will not run the missed job in the morning when you turn it on.

Related Links
[mkaz.com] At Command Mac OS X and eBay – at is similar to cron but for one time jobs, not reoccuring

%d bloggers like this: