Subversion self tutorial

March 4th, 2010 madiga No comments

Subversion is an open-source version control system similar to CVS except it’s supposed to be a replacement for CVS. It has some advantages of over CVS such as better management of files and directories, renaming, branching as of course reverting.

As I’ve indicated before, one of the main reasons I keep adding articles to this blog is for my own reference as well. This way at some point in the future, If I need to lookup something, I can simply visit the site and find what I need.

At the same time, I hope that these short articles also benefit some of you as well.

  • Create a repository mynitor.com:
$ cd /data/repositories

$ svnadmin create mynitor.com
  • Import project mynitor.com:
$ svn mkdir file:///data/repositories/mynitor.com

$ cd /home/mynitor.com

$ svn import file:///data/repositories/mynitor.com
  • Checkout mynitor.com project, make changes and re-submit to svn:
$ svn checkout file:///data/repositories/mynitor.com

$ svn commit
  • Compare revisions:
$ svn compare -r R1:R2 [filename]
  • Revert to previous version
$ svn update -r R
  • Checkout over HTTP if server is using WebDAV
$ svn co --username mynitor --password myblog 

http://svn.mynitor.com/mynitor/branches/live/
  • And my favorite, checkout over SSH
 $ svn co svn+ssh://mynitor@svn.mynitor.com/mynitor/branches/live/

You will find svn help very helpful.

Categories: General Tags:

Daemonize any process in Linux

February 28th, 2010 madiga 1 comment

Any user or admin more than likely faced or will face a situation where their command will take a long time to complete and at the same time you’d want to logout and go home.  If user’s shell exits, it sends a SIGHUP signal to it’s children killing them all.

Well one of the reasons why Linux is so awesome is that it has a solution for almost any situation.  So in this case, if the job is preceded by the nohup command, the program ignores SIGHUP and will continue to run on the system until completion. Processes run by nohup are immnue to SIGHUP and SIGQUIT signals.

By using nohup, it releases the command to the system level and it becomes independent of your shell and functions as a system daemon.  You can also run your command and redirect output to a log to scan through later.  Here are some examples of using nohup:

$ nohup myprogram &

  • The above command starts myprogram in the background in such a way that the subsequent logout does not stop it.  By default, nohup.out is created and captures all the output.

$ nohup myprogram > /tmp/output.log 2>&1 &

  • The above redirect output to a file other than the nohup.out.

If you already have something running in bg without using the nohup command, you can easily bring nohup to the picture:

$ myprogram &
$ nohup -p `pgrep myprogram`

  • myprogram is now preceded by nohup.

$ nohup find / -name ‘*’ -size +1000k > log.txt

  • The above example runs the find command, detaches itself in bg as a daemon and continues to run until completion.
Categories: linux Tags:

Kubuntu is awesome!

February 27th, 2010 madiga 5 comments

Why do many people use Gnome as their window manager for Linux?  It seems Ubuntu.com markets the distribution which contains Gnome pre-installed. For example, the live CD contains Gnome and for this reason many new users seem to think this is their limitation as far desktop interface goes.

However if there are users who are transitioning from Window to Linux for the first time, then KDE is probably a more suitable candidate for it’s familiar style to Windows and ease of moving around.

Gnome feels more of a Unix desktop for average Linux users but with KDE, new users would immediately find themselves very comfortable with it.

Just click on the big “K” icon and you’ll see the familiar look and feel that Windows has.   So my advice for what it’s worth is to give KDE a try.  Download the Kubuntu distribution instead and give it a shot instead of the default distribution.  If you already have Ubuntu installed and want to give KDE a try, simply type:

sudo apt-get install kubuntu-desktop

You can decide to use kdm (KDE) or gdm (Gnome) as your default but you can keep it as gdm for now and if you like KDE more, you can always make it a default later.  The login process usually asks if you want to make KDE your default or not.

If you find yourself not liking KDE, then simply remove by typing:

sudo aptitude remove kubuntu-desktop

Enjoy KDE, I am.

Categories: linux Tags:

Command line calculator for Linux, calculate big with bc

February 25th, 2010 madiga 3 comments

If you’re a command line freak, you’ve probably use expr for common math calculations but did you know that the bc command allows you to do similar math calculations and is more powerful when it comes to bigger calculations?

bc is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language. A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.)

If the above man page description don’t make any sense yet, then just remember that bc is a command line calculator. The nice thing about bc is that it accepts inputs from files, from standard output and this allows the command line user to pipe data out for quick calculations. The syntax for basic calculation is very similar to Google’s calculator.

Here are some basic examples:

$ cat file.txt
5+5
$ bc < file.txt
10
$
echo 2+2 | bc
4

It’s possible to use basic math with variables:

$ A=9
$ B=6
$ C=$ ((A+B))
$ echo $C
15

Some more basic examples of addition, subtraction, multiplication and division:

$ echo ‘50+20′ | bc
70
$ echo ‘50-20′ | bc
30
$ echo ‘50*20′ | bc
1000
$ echo ‘50/20′ | bc
2

There is a variable called scale and using it adds number of digits which follow the decimal point. By default scale is 0. So the above example shows 2 but if scale variable was used, the result could be displayed in x # of digits.

$ echo ’scale=1;50/20′ | bc
2.5

How about square root, and power:

$ echo ’scale=15;sqrt(8)’ | bc
2.828427124746190
$ echo ‘4^4′ | bc
256

Convert from decimal to hexadecimal, from decimal to binary and from binary back to decimal:

$ echo ‘obase=16;255′ | bc
FF
$ echo ‘obase=2;22′ | bc
10110
$ echo ‘ibase=2;obase=A;10110′ | bc
22

bc in interactive mode:

$ bc
4*4
16
13*13
169
scale=10
199/3
66.3333333333
2^32
4294967296

As you can see, it’s not shy about displaying the big value results. Here are some more resources to help you explore bc further:

  1. man bc (Yes man page, it’s got everything you’ll need)
Categories: linux Tags:

14 useful ARP monitoring tools

February 13th, 2010 madiga No comments

Some say ARP is an old school crap that it’s no longer useful in this modern day and age.  Those who say this, don’t know what it’s all about.  ARP is used to link IP address to a system’s physical MAC address in a local network, this is how the servers identify each other.

By understanding ARP and knowing how to use the arp utility, one can troubleshoot network related issues faster.  In this article, we’ve put together 14 tools specifically used to to deal with ARP related monitoring and troubleshooting.

1) Arping

- an ARP level ping utility. It’s good for finding out if an IP is taken before you have routing to that subnet. It can also ping MAC addresses directly.

2) arp-scan

-  sends ARP (Address Resolution Protocol) queries to the specified targets, and displays any responses that are received. It allows any part of the outgoing ARP packets to be changed, allowing the behavior of targets to non-standard ARP packets to be examined. The IP address and hardware address of received packets are displayed, together with the vendor details. These details are obtained from the IEEE OUI and IAB listings, plus a few manual entries. It includes arp-fingerprint, which allows a system to be fingerprinted based on how it responds to non-standard ARP packets.

3)  arpalert

- uses ARP address monitoring to help prevent unauthorized connections on the local network. If an illegal connection is detected, a program or script is launched, which could be used to send an alert message, for example.

4)  parprouted

- a daemon for transparent IP (Layer 3) proxy ARP bridging. This is useful for creation of transparent firewalls and bridging networks with different MAC protocols. Also, unlike standard bridging, proxy ARP bridging allows to bridge Ethernet networks behind wireless nodes without using WDS or layer 2 bridging.

5)  ARPSpoofDetector

-performs active and passive detection of ARP spoofing and IP (IPv4) address collision. The program can send healing packets with regular ARP information.

6)  Local IP Takeover

- provides network link redundancy within a single server that has multiple network interface cards (NICs) with each NIC connected to separate network switches. If the primary NIC fails (i.e. it cannot ping its default gateway), the “service” IP (the IP that the outside world connects to) will automatically float to the secondary NIC and a specially crafted ARP (utilizing send_arp) will be broadcast on the local network, thereby instructing all other hosts to update their local ARP cache. The result is minimal service downtime. Plus, no manual intervention is required in the event that a network card, cable, or switch breaks.

7) ARP Tools

- Collection of libnet and libpcap based ARP utilities. It currently contains ARP Discover (arpdiscover), an Ethernet scanner based on ARP protocol; ARP Flood (arpflood), an ARP request flooder; and ARP Poison (arppoison), for poisoning switches’ MAC address tables.

8 )  Gnome ARP

- an ARP monitoring program written on Gnome with the GTK toolkit and Ruby. It takes ARP tables and some system variables via SNMP and ARP protocols and determines whether any machines have changed their IP address. It is useful for detecting new machines on the network and detecting which machine have changed addresses. It is intended especially for network admins.

9) Arphound

- a tool that listens to all traffic on an ethernet network interface. It reports IP/MAC address pairs as well as events such as IP conflicts, IP changes, IP addresses with no RDNS, various ARP spoofing, and packets not using the expected gateway. Reporting is done to stdout, to a specified file, or to syslog in a format that can be easily parsed by scripts.

10)  wakearp

- a small utility to induce ARP resolution for any listening IP address in the local /24 subnet.

11)  MasarLabs NoArp

- a Linux kernel module that filters and drops unwanted ARP requests. It is useful when you need to add an alias to the loopback interface to use a load balancer.

12)  Antidote

- a detector for ARP poisoning on a switched network.

13)  arprelease

- a small libnet-based tool to flush ARP cache entries from devices like Cisco routers to move an IP from one Linux box to another.

14)  ARPoison

- a network analysis tool that sends ARP packets to/from specified hardware and protocol addresses.

Categories: tools Tags:

15 Remote Desktop Solutions for Linux.

February 7th, 2010 madiga 10 comments

There are a wide range of remote desktop applications that are available that can be used to connect to Windows environment but there aren’t too many that can be used to remote desktop from Linux to Linux or Windows to Linux. With this I mean, getting entire desktop of remote Linux environment on your local workstation.

Most people who are used to a Unix-style environment know that a machine can be reached over the network at the shell level using utilities like telnet or ssh. And some people realize that X Windows output can be redirected back to the client workstation. But many people don’t realize that it is easy to use an entire desktop over the network. There are a several of open source applications that can be used to achieve this.

1)  VNC (Virtual Network Computing) is a remote display system which allows the user to view the desktop of a remote machine anywhere on the internet. It can also be directed through SSH for security.

Basically you install VNC server on the server and install client on your local PC. Setup is extremely easy and server is very stable. On client side, you can set the resolution and connect to IP of VNC server. It can be a bit slow compared to Windows remote desktop and also has the tendency to take more time refreshing over low-bandwidth links. All in all VNC is an amazing piece of free software that gets the job done.

There is RealVNC , TightVNC and UltraVNC. Each has it’s advantages and disadvantages. Most popular one is RealVNC but if you’re upto it, experiment with all three and choose the one that works for you best. By default, communication between client and server is in clear text on port 5900. However, you can easily route all traffic via SSH tunnel. Here is a quick way of setting it up if you have access to command line shell:

ssh -ND 5900 <user>@remote.server.com

When you get prompted, enter your password. Pop open VNC client and connect to ‘localhost’. This’ll route your connection to VNC server on remote machine.

You can download VNC from:

2)  Then there is FreeNX. FreeNX is a system that allows you to access your desktop from another machine over the internet. You can use this to login graphically to your desktop from a remote location. One example of its use would be to have a FreeNX server set up on your home computer, and graphically logging in to the home computer from your work computer, using a FreeNX client. It provides near local speed application responsiveness over high latency, low bandwidth links.

FreeNX can be configured to run via SSH without any tunneling. It binds to your existing SSH install. Instead of guiding you through the installation of FreeNX in this article, you can visit the following URLs that’ll guide you through the installation on Ubuntu:

3) The third free application is 2X Terminal Server for Linux. 2X TerminalServer for Linux is an Open Source project, licensed under the GPL and is free of charge. As far as performance goes, NoMachine’s technology is on par with Windows’ own Remote Desktop Protocol (RDP) suite, better than VNC. Both X2 and FreeNX is based on NoMachine technology.

Here are some quick links if you’re interested in using this software:

4) Then there is is XDMCP. The X Display Manager Control Protocol uses UDP port 177. Compared to the list above, it’s not as easy to setup for remote desktop but it’s the original way of doing this on Linux. You can get setup instructions and other tips in the following URL:

5) CygwinX. A complete Linux emulation on Windows. You’ll find every tool and app that you have on Linux on Cygwin.

6) XRDP. RDP server that runs on Linux, thus allowing you to use Windows Remote Desktop Client or rdesktop to connect.

7) x2vnc – great little utility that allows you to tie a linux and windows (or anything that can run the vncserver) together with a ingle keyboard/mouse, avoiding the need for a switcher box. Mousing cross screens transparently switches between machines, and cut and aste works.

8 ) Xming – t’s a great and lightweight implementation of X11 for Windows that allows you to connect to a Linux box.

9) KDE Desktop Sharing (formerly krfb) – part of KDE since version 3.1. It is located in the kdenetwork package. If your distribution splits the KDE applications into separate packets, you may find the client as ‘krdc’ and the server as ‘krfb’. Also uses VNC technology.

10) X-Win32 - Top rated PC X server solutions for Windows PCs connecting to remote Unix and Linux host systems. Works well over SSH.

11) Single Click UltraVNC – In case you would like to remote control without any software installed on the target computer you need UltraVNC SC. The user on the to be controlled computer needs to simply click on a web page and remote controlling begins.

12) CrossLoop – CrossLoop is a FREE secure screen sharing utility designed for people of all technical skill levels. CrossLoop extends the boundaries of VNC’s traditional screen sharing by enabling non-technical users to get connected from anywhere on the Internet in seconds without changing any firewall or router settings.

13) Thinstation – Although not a remote desktop app but worth mentioning here. Thin client linux distro for terminals using std. x86 hw. It can boot from network, pxe, syslinux,loadlin, CD, floppy or flash-disk and connect to servers using VNC, RDP, XDM, SSH and etc.

14) rdesktop - an open source client for Windows NT Terminal Server and Windows 2000/2003 Terminal Services, capable of natively speaking Remote Desktop Protocol (RDP) in order to present the user’s NT desktop. rdesktop currently runs on most UNIX based platforms with the X Window System, and other ports should be fairly straightforward.

While you’re at it, get grdesktop from (http://www.nongnu.org/grdesktop/). It is a GNOME frontend, for rdesktop. It can save several connections (including their options), and browse the network for available terminal servers.

15) ssh -X – You can check out this great article written by a slashdot user sometime ago.

Windows to Mac / Mac to Windows

1) RDP Client for Mac allows you to connect to a Windows-based computer and work with programs and files on that computer from your Macintosh computer.

2) OSXVnc – Vine Server is a full featured VNC server for Mac OS X providing remote access to the GUI, keyboard and mouse using Vine Viewer or any other VNC client.

3) Chicken of the VNC – A VNC client allows one to display and interact with a remote computer screen. In other words, you can use Chicken of the VNC to interact with a remote computer as though it’s right next to you.

Unfortunately I was not able to find too many available to connect to Mac from Windows other than VNC. I think Windows need to support RDP into Mac. Many people would benefit from this.

If I am missing anything from the list, please let me know.

Categories: linux, tools Tags:

Tiny Linux Command Reference

February 5th, 2010 madiga No comments

Tiny Linux Command Reference

ls List files/directories in a directory
cat <filename> Read a file.
cp Copy a file
mv Move a file
rm Delete a file
chmod Changes file access permissions
chown Changes file ownership
grep Looks for patterns in files
ln Create’s “links” between files and directories
wc Word count
find Find files and directories.
locate Locate a file name/directory
file <filename> Guess type of file
touch Create an empty file
od View binary files and data
pwd Print working directory
hostname Print name of localhost
whoami Print login name
id Print user id
date Print or change date on system
time <command> Determine the amount of time it takes for a process to complete
who Check who is logged on the system
last Show users last logged-in
uptime Check system uptime as well as load average details
ps List process run by user
ps auxw List all the process on the system
top Keep listing currently running processes
uname -a Info about your local server
lsmod Show the kernel modules currently loaded
dmesg Print kernel messages
tail Similar to cat, but only reads the end of the file
head Similar to tail, but only reads the top of the file
more Llike cat, but opens the file one screen at a time rather
than all at once
less Like more, but less. (LOL *BURP*)
netstat Shows all current network connections.
ifconfig Display info on the network interfaces
ping Sends test packets to a specified server
nslookup Lookup a host/domain.
dig Similar to nslookup.
sudo You know, sudo.
kill terminate a system process
killall Kill program(s) by name
du Shows disk usage.
free Memory info
man Display the contents of the system manual pages
reboot Reboot the machine.
tar Creating and Extracting .tar files
gzip Compress in gzip
zip Compress in zip
unzip Uncompress a zip file
compress Compress files .Z
uncompress Uncompress .Z files
bzip2 Compress files in bzip2 forma

Also check out The Ultimate Linux Reference Guide for Newbies

Categories: linux Tags:

Cool Desktop Multiplier

February 4th, 2010 madiga No comments

I came across this neat application called Userful Desktop Multiplier. It is a virtualized X server that turns one computer into ten “workstations” by using extra video cards, keyboards, and monitors. This approach offers significantly higher performance and lower hardware costs than Thin Client or LTSP.

It installs on most popular Linux distributions (Red Hat, Novell/SuSE, Fedora, Mandriva, Xandros, Linspire, Ubuntu, etc.). It supports USB touch screens (Elotouch, Microtouch), card-swipes, barcode scanners, as well as all virtually all video cards supported by X. It features easy setup and graphical configuration. Download it from here.

Desktop Multiplier

Categories: linux, tools Tags:

15 methods to boost your PHP based website’s performance

February 3rd, 2010 madiga 14 comments

PHP is great for writing quick dynamic stuff for your website. Just a couple of lines of code can be written in 2 mins to insert or retrieve data from db. But with ease there is also some pain… the downside is that each request for a dynamic page can trigger multiple db queries, processing of output, and finally formatting to display on browser. This process can eventually be slow on larger sites or slower servers.

In this article, we’ve put together the list of caching plugins and techniques which can be used to improve your website performance.

  1. Caching output in PHP – Caching of output in PHP is made easier by the use of the output buffering functions built in to PHP 4 and above.
  2. PHP Caching to Speed up Dynamically Generated Sites – Instead of regenerating the page every time, the scripts running this site generate it the first time they’re asked to, then store a copy of what they send back to your browser. The next time a visitor requests the same page, the script will know it’d already generated one recently, and simply send that to the browser without all the hassle of re-running database queries or searches.
  3. Alternative PHP Cache – A free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
  4. PHP-Cache-Kit – Dramatically speed up your site with this easy-to-use PHP caching kit. A slim little PHP class which allow you to quickly and easily implement module-level caching into your PHP projects.
  5. Unearth PHP Cache Engine – A flexible, easy-to-use system for caching PHP pages. It is really intended to cache a series of parts of a single page independently, each with its own refresh requirements. Caching of this sort can dramatically decrease page rendering time.
  6. PHP Cache Class – A PHP class that caches output generated by PHP files and uses the cached version instead of generating the content again and again. Cache files expire after a specified amount of time.
  7. PHP Accelerator – A plugin PHP Zend engine extension that provides a PHP script cache and is capable of delivering a substantial acceleration of PHP scripts without requiring any script changes, loss of dynamic content, or other application compromises.
  8. gCache – A PHP class that can be used to capture and cache Web page content. It can store cached content in files of a given directory.
  9. Skycache – A free, lightweight, and fast page cache for PHP 4 and PHP 5. Once a dynamic page has been computed, it is stored in a page cache. If a query for the same URL is made afterwards, the content is immediately served from the cache instead of processing the script again. The end result is a significant speedup and a slightly reduced server load.
  10. eAccelerator – A further development of the mmcache PHP accelerator and encoder. It increases the performance of PHP scripts by caching them in a compiled state, so that the overhead of compiling is almost completely eliminated.
  11. PHP FastFileCache – Caches output from dynamic PHP scripts, and stores them in files for fast retrieval under high server load. It supports a global timeout setting for maximum cache age, as well as per-file timeout overrides. It also implements file locking, to prevent data corruption and unnecessary processing.
  12. CacheIt – A PHP class designed to facilitate caching.
  13. Turck MMCache for PHP – A free PHP accelerator, optimizer, encoder, and dynamic content cache. It increases performance of PHP scripts by caching them in a compiled state, so that the overhead of compiling is almost completely eliminated.
  14. TinyButStrong – A template class for PHP that allows you to generate HTML pages using MySQL, PostgreSQL, SQLite in native, and any other databases.
  15. Boost website performance in 5 seconds! – Not exactly caching but simple enough to implement a quick fix.

Did we miss something? Please let us know in the comment area.

Categories: PHP Tags: ,

Top 8 MySQL Management Tools

February 1st, 2010 madiga No comments

A large percentage of small to medium sized websites depend on Mysql server to support their db infrastructure. Working with it is as easy is saying it and for some reason there are numerous web and non-web administration software written specifically to manage a Mysql server and sites running on it. This article lists quite a few of them which you may find useful.

  1. NG-Admindesigned for the content management of MySQL databases. It allows the user to browse, add, edit, and delete data. It is somewhat similar to phpMyAdmin, but specializes in editing the content of Web sites, not the database structures. Its features are very easy to use and highly tunable.
  2. PHP Mini SQL Admina light, standalone script for accessing MySQL databases. It is intended for Web developers.
  3. FlashMyAdmin - Flash-based MySQL administration project. It features multiple database management, import/export (SQL, XML, CSV), internationalization, and help. It also allows video, audio, images, and movieclip files to be shown directly within the interface.
  4. phpMyAdmin - a tool written in PHP intended to handle the administration of MySQL over the Web. It can create, rename, and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields, create dumps of tables and databases, export/import CSV data and administrate one single database and multiple MySQL servers.
  5. jspMyAdmin – a clone of the very popular phpMyAdmin, but written in JSP. It provides MySQL database administration over the Web.
  6. RUIDB – a simple tool for working with MySQL using a Web browser. It was made to enable users with little knowledge of MySQL to add/edit/delete/view table rows. It is also a nice tool for admins or Web site authors.
  7. KooDB – a MySQL database administration frontend that features an intuitive interface. It aims to give substantial control over MySQL without adding all the complicated options of phpMyAdmin.
  8. MySQL Administrator – a powerful visual administration console for MySQL, which allows the user to easily administer their MySQL environment, and gain better visibility of how their databases are operating. It is available with native GUI interfaces for Windows, Linux, and Mac OS X.

There are others but who cares once you get used to administration via command line, nothing comes even close to beating it.

Categories: mysql Tags: