Search This Blog

Wednesday, March 26, 2008

EXTJS HELP

Please some one teach me extjs, i am tired of it, plz help me................

Tuesday, March 25, 2008

MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN

In a database such as MySQL, data is divided into a series of tables (the "why" is beyond what I'm writing today) which are then connected together in SELECT commands to generate the output required. I find when I'm running MySQL training, people often get confused between all the join flavours. Let me give you an example to see how it works. If this isn't quite the question you're looking to have answered, we've got a MySQL IAQ (Infrequently Answered Questions that may help you First, some sample data: Mr Brown, Person number 1, has a phone number 01225 708225 Miss Smith, Person number 2, has a phone number 01225 899360 Mr Pullen, Person number 3, has a phone number 01380 724040 and also: Person number 1 is selling property number 1 - Old House Farm Person number 3 is selling property number 2 - The Willows Person number 3 is (also) selling property number 3 - Tall Trees Person number 3 is (also) selling property number 4 - The Melksham Florist Person number 4 is selling property number 5 - Dun Roamin.

mysql> select * from demo_people;

+------------+--------------+------+

| name       | phone        | pid  |

+------------+--------------+------+

| Mr Brown   | 01225 708225 |    1 |

| Miss Smith | 01225 899360 |    2 |

| Mr Pullen  | 01380 724040 |    3 |

+------------+--------------+------+

3 rows in set (0.00 sec)



mysql> select * from demo_property;

+------+------+----------------------+

| pid  | spid | selling              |

+------+------+----------------------+

|    1 |    1 | Old House Farm       |

|    3 |    2 | The Willows          |

|    3 |    3 | Tall Trees           |

|    3 |    4 | The Melksham Florist |

|    4 |    5 | Dun Roamin           |

+------+------+----------------------+

5 rows in set (0.00 sec)



mysql>

If I do a regular JOIN (with none of the keywords INNER, OUTER, LEFT or RIGHT), then I get all records that match in the appropriate way in the two tables, and records in both incoming tables that do not match are not reported:

mysql> select name, phone, selling

from demo_people join demo_property

on demo_people.pid = demo_property.pid;

+-----------+--------------+----------------------+

| name      | phone        | selling              |

+-----------+--------------+----------------------+

| Mr Brown  | 01225 708225 | Old House Farm       |

| Mr Pullen | 01380 724040 | The Willows          |

| Mr Pullen | 01380 724040 | Tall Trees           |

| Mr Pullen | 01380 724040 | The Melksham Florist |

+-----------+--------------+----------------------+

4 rows in set (0.01 sec)



mysql>

If I do a LEFT JOIN, I get all records that match in the same way and IN ADDITION I get an extra record for each unmatched record in the left table of the join - thus ensuring (in my example) that every PERSON gets a mention:

mysql> select name, phone, selling

from demo_people left join demo_property

on demo_people.pid = demo_property.pid;

+------------+--------------+----------------------+

| name       | phone        | selling              |

+------------+--------------+----------------------+

| Mr Brown   | 01225 708225 | Old House Farm       |

| Miss Smith | 01225 899360 | NULL                 |

| Mr Pullen  | 01380 724040 | The Willows          |

| Mr Pullen  | 01380 724040 | Tall Trees           |

| Mr Pullen  | 01380 724040 | The Melksham Florist |

+------------+--------------+----------------------+

5 rows in set (0.00 sec)



mysql>

If I do a RIGHT JOIN, I get all the records that match and IN ADDITION I get an extra record for each unmatched record in the right table of the join - im my example, that means that each property gets a mention even if we don't have seller details:

mysql> select name, phone, selling

from demo_people right join demo_property

on demo_people.pid = demo_property.pid;

+-----------+--------------+----------------------+

| name      | phone        | selling              |

+-----------+--------------+----------------------+

| Mr Brown  | 01225 708225 | Old House Farm       |

| Mr Pullen | 01380 724040 | The Willows          |

| Mr Pullen | 01380 724040 | Tall Trees           |

| Mr Pullen | 01380 724040 | The Melksham Florist |

| NULL      | NULL         | Dun Roamin           |

+-----------+--------------+----------------------+

5 rows in set (0.00 sec)



mysql>

An INNER JOIN does a full join, just like the first example, and the word OUTER may be added after the word LEFT or RIGHT in the last two examples - it's provided for ODBC compatability and doesn't add an extra capabilities.

Wednesday, March 12, 2008

Simple Network Management Protocol

The Simple Network Management Protocol (SNMP) is an application layer protocol that facilitates the exchange of management information between network devices. It is part of the Transmission Control Protocol/Internet Protocol (TCP/IP) protocol suite. SNMP enables network administrators to manage network performance, find and solve network problems, and plan for network growth.

Figure 1 SNMP Facilitates the Exchange of Network Information Between Devices

SNMP Basic Components

An SNMP-managed network consists of three key components: managed devices, agents, and network-management systems (NMSs).

A managed device is a network node that contains an SNMP agent and that resides on a managed network. Managed devices collect and store management information and make this information available to NMSs using SNMP. Managed devices, sometimes called network elements, can be routers and access servers, switches and bridges, hubs, computer hosts, or printers.

An agent is a network-management software module that resides in a managed device. An agent has local knowledge of management information and translates that information into a form compatible with SNMP.

An NMS executes applications that monitor and control managed devices. NMSs provide the bulk of the processing and memory resources required for network management. One or more NMSs must exist on any managed network.

Figure 2 An SNMP-Managed Network Consists of Managed Devices, Agents, and NMSs

SNMP Basic Commands

Managed devices are monitored and controlled using four basic SNMP commands: read, write, trap, and traversal operations.

The read command is used by an NMS to monitor managed devices. The NMS examines different variables that are maintained by managed devices.

The write command is used by an NMS to control managed devices. The NMS changes the values of variables stored within managed devices.

The trap command is used by managed devices to asynchronously report events to the NMS. When certain types of events occur, a managed device sends a trap to the NMS.

Traversal operations are used by the NMS to determine which variables a managed device supports and to sequentially gather information in variable tables, such as a routing table.

SNMP Management Information Base

A Management Information Base (MIB) is a collection of information that is organized hierarchically. MIBs are accessed using a network-management protocol such as SNMP. They are comprised of managed objects and are identified by object identifiers.

A managed object (sometimes called a MIB object, an object, or a MIB) is one of any number of specific characteristics of a managed device. Managed objects are comprised of one or more object instances, which are essentially variables.

Two types of managed objects exist: scalar and tabular. Scalar objects define a single object instance. Tabular objects define multiple related object instances that are grouped in MIB tables.

An example of a managed object is atInput, which is a scalar object that contains a single object instance, the integer value that indicates the total number of input AppleTalk packets on a router interface.

An object identifier (or object ID) uniquely identifies a managed object in the MIB hierarchy. The MIB hierarchy can be depicted as a tree with a nameless root, the levels of which are assigned by different organizations. Figure 56-3 illustrates the MIB tree.

The top-level MIB object IDs belong to different standards organizations, while lower-level object IDs are allocated by associated organizations.

Vendors can define private branches that include managed objects for their own products. MIBs that have not been standardized typically are positioned in the experimental branch.

The managed object atInput can be uniquely identified either by the object name—iso.identified-organization.dod.internet.private.enterprise.cisco.temporary variables.AppleTalk.atInput—or by the equivalent object descriptor, 1.3.6.1.4.1.9.3.3.1.

Figure 56-3 The MIB Tree Illustrates the Various Hierarchies Assigned by Different Organizations

For more Information on SNMP click here SNMP

Transmission Control Protocol (TCP)

Whereas IP focuses on getting data across the vast network from one computer to another, TCP assures that the data gets sucked off the network connected computer and delivered to the receiving application and that the data is delivered in the correct sequence.

Recall that since IP chops messages up into packets, we need to assure that the messages are assembled correctly at the other end of transport. And if any errors occur during transport, such as message degradation or the loss of some packets, the sender will know to resend.

TCP also tries to optimize network bandwidth by controlling the flow of information dynamically, slowing down as network traffic becomes congested.

Internet Protocol (IP)

Internet Protocol (IP) is a connectionless protocol that gateways use to identify networks and paths to networks and hosts. In other words, IP handles the routing of data between networks and nodes on those networks.

You will be familiar with IP because in order to address web pages, you must use domain names like www.barclayscapital.com, or their numerical counterparts called IP addresses.

NOTE: Domain names are far easier to remember than IP addresses so we usually use domain names instead of IP addresses and rely upon Domain Name Servers to tie domain names to their IP address counterparts behind the scenes.

IP addresses are unique sets of four period delimited octets that represent individual hosts on specific networks. A TCP/IP octet is a number between 0 and 255. Thus, an IP Address might look something like:

30.85.1.26

which you might read as something like "computer named 26, on network 1, on host 85, of network 30."

NOTE: 255 is usually a reserved number which means broadcast to all hosts and 0 represents "this", or the current host.

Besides defining the address scheme, IP also handles the transmission of data from an originating computer to the computer specified by the IP address. It does so by breaking up large, unwieldy chunks of data into easily manageable IP packets that it can deliver across the network.

That is why we talk of IP being a connectionless protocol. In an effort to better manage network traffic, IP specifies the protocol for breaking single messages into a slew of portions. Each portion is responsible for finding its way across the network based on changing traffic congestion and the IP protocol.

Each time a message arrives at an IP router, the router decides where to send it next. There is no concept of a session with a preselected path for all traffic. Routers can send data along the path of least resistance regardless of local network traffic congestion.

If one phone line on the network breaks down, for example, traffic can still reach its destination through a roundabout path.

TCP/IP

TCP/IP (The Transmission Control Protocol/Internet Protocol) is the protocol suite that drives the Internet. Specifically, TCP/IP handles network communications between network nodes (computers, or nodes, connected to the net).

The suite is actually composed of several protocols including IP which handles the movement of data between host computers, TCP which manages the movement of data between applications, UDP which also manages the movement of data between applications but is less complex and reliable than TCP, and ICMP which transmits error messages and network traffic statistics.

Tuesday, March 11, 2008

How do I find out screen resolution of my Linux desktop?

It refers to the clarity of an image on screen. Screen resolution suggests the number of dots or pixels on the entire computer screen. For example, when you say a 640 x 480 screen resolution then all you means is individual 640 dots on each 480 lines i.e. 307K pixels.

Use xdpyinfo command to find out current screen resolution:

$ xdpyinfo  | grep 'dimensions:'

dimensions: 800×600 pixels (283×212 millimeters)

You can also use xrandr command:

$ xrandr | grep '*'

*0 1024 x 768 ( 283mm x 212mm ) *61

You can also use Desktop tools to find out current desktop screen resolution:

(A) Gnome Desktop

Click Gnome Desktop menu > Preferences > Screen resolution

(B) KDE Desktop

  1. Click on K desktop Icon > Select Control Center
  2. Select Peripherals (under Index tab) > Select Display
  3. It will display Screen resolution or size

See Screen resolution at wikipedia.

How do I find out Linux System Memory Utilization?

Q. How do I find out System / Server Memory Utilization under RHEL / CentOS / any other Linux distribution?

A. You need to use free command which, displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.

free command example

Type the free command at shell prompt: $ free $ free -m Output:

             total       used       free     shared    buffers     cached
Mem:          2010       1965         45          0        152        776
-/+ buffers/cache:       1036        974
Swap:         2047        137       1910

vmstat command

vmstat command provides more information : $ vmstat Output:

procs ———–memory———- —swap– —–io—- –system– —–cpu——
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
0  0 140480  43636 158196 797692    1    0   108   220    1    4  7  5 87  1  0

Understanding vmstat memory options

  • swpd: the amount of virtual memory used.
  • free: the amount of idle memory.
  • buff: the amount of memory used as buffers.
  • cache: the amount of memory used as cache.
  • inact: the amount of inactive memory. (-a option)
  • active: the amount of active memory. (-a option)

$ vmstat -a Output:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
0  1 140480  37376 109516 1730040    1    0   108   220    1    4  7  5 87  1  0

The following command displays one new line of utilization data every second $ vmstat 1 The following command displays one new line per 2 second, but only for the next 10 seconds: $ vmstat 2 10 Output:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
4  0 139216  23508 130644 1723680    1    0   108   220    1    5  7  5 87  1  0
2  0 139216  23252 130668 1723816    0    0     0   410 3242 11472  9  7 84  0  0
1  0 139216  23120 130656 1724012    0    0     0   750 3280 11592  3  6 90  1  0
0  0 139216  22996 130588 1724180    0    0     0   426 3272 11052  2  5 93  0  0
2  0 139216  20988 129932 1726980    0    0     6  1146 3353 12105 14  9 74  2  0
1  0 139216  20244 129900 1727216    0    0     0   392 3238 11752  8  7 85  0  0
1  0 139216  20120 129868 1727352    0    0     0   444 3197 11173  2  5 93  0  0
1  0 139216  25964 129852 1721044    0    0     0   268 3147 9269  1  4 95  0  0
3  0 139216  25964 129748 1721196    0    0     2   132 3199 10540  1  4 95  0  0
1  0 139216  25964 129676 1721332    0    0     0   456 3213 10608  2  4 93  1  0

Monday, March 10, 2008

How to find out or Learn harddisk size in Linux or UNIX

Q. How do I find out or learn hard disk size in Linux? A. Under Linux and UNIX you can use df command. df command displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown. Task: Display hard disk partition size $ df Output: Filesystem 1K-blocks Used Available Use% Mounted on /dev/hdb1 19228276 14699744 3551784 81% / tmpfs 384300 4 384296 1% /dev/shm /dev/hdb5 27917308 23883184 2615988 91% /data/network Task: Display hard disk partition size in Mega bytes $ df -H Output: Filesystem Size Used Avail Use% Mounted on /dev/hdb1 20G 16G 3.7G 81% / tmpfs 394M 4.1k 394M 1% /dev/shm /dev/hdb5 29G 25G 2.7G 91% /data/network Task: Display TOTAL hard disk size fdisk command is partition table manipulator for Linux. But it can be use to display total hard disk site. You must type the following command as the root user: # fdisk -l | grep Disk Output: Disk /dev/hda: 20.0 GB, 20060651520 bytes Disk /dev/hdb: 80.0 GB, 80060424192 bytes

Linux : How to delete file securely

How to remove files securely so that it cannot be undeleted. Peter Gutmann paper “Secure Deletion of Data from Magnetic and Solid-State Memory” has very good information. Here are some commands/tools available under Debian GNU/Linux (it should work with other Linux distributions) to delete file securely.

srm: Securely remove files or directories

This command is a replacement for rm command. It works under Linux/BSD/UNIX-like OSes. It removes each specified file by overwriting, renaming, and truncating it before unlinking. This prevents other people from undelete or recovering any information about the file from the command line. Because it does lots of operation on file/directory for secure deletion, it also takes lot of time to remove it. Download srm from http://sourceforge.net/projects/srm (RPM file is also available for RPM based Linux distributions)

i) Untar and install the srm:

# ./configure
# make
# make install 

ii) How to use srm? srm syntax is like rm command. Read man srm. Here is simple example:

$ srm privateinfo.doc

wipe: It is a secure file wiping utility

Download wipe from http://wipe.sourceforge.net/ i) Untar and install the wipe

# ./configure
# make
# make install

ii) How to use wipe?

$ wipe filename

Read man page of wipe for information.

shred: Delete a file securely, first overwriting it to hide its contents.

It is available on most of Linux distributions including Debian GNU/Linux. To remove file called personalinfo.tar.gz :

$ shred -n 200 -z -u  personalinfo.tar.gz

Where,

  • -n: Overwrite N (200) times instead of the default (25)
  • -z: Add a final overwrite with zeros to hide shreddin
  • -u: Truncate and remove file after overwriting

Read the man page of shred(1) for more information. Most of these utilities are not effective (read as useless) only if :

  • File system is log-structured or journaled filesystems, such as JFS, ReiserFS, XFS, Ext3 etc
  • Your filesystems is RAID-based, compressed filesystem etc
  • In addition, file system backups and remote mirrors may contain copies of the file that cannot be removed by these utilities.

Linux install and configure pound reverse proxy for Apache http / https web server

Q. How do I install and configure pound reverse proxy for Apache web sever under Debian Linux? A. Pound is a reverse-proxy load balancing server. It accepts requests from HTTP / HTTPS clients and distributes them to one or more Web servers. The HTTPS requests are decrypted and passed to the back-ends as plain HTTP. It will act as: a) Server load balancer b) Reverse proxy server c) Apache reverse proxy etc d) It can detects when a backend server fails or recovers, and bases its load balancing decisions on this information: if a backend server fails, it will not receive requests until it recovers e) It can decrypts https requests to http ones f) Rejects incorrect requests h) It can be used in a chroot environment (security feature)

If more than one back-end server is defined, Pound chooses one of them randomly, based on defined priorities. By default, Pound keeps track of associations between clients and back-end servers (sessions).

Install Pound Software

Type the following command to install pound: $ sudo apt-get install pound If you are using RHEL / CentOS, grab pound rpm here and type the command: # rpm -ivh pound* If you are using FreeBSD, enter: # cd /usr/ports/www/pound/ && make install clean

How it works?

  • Let us assume your public IP address 202.54.1.5.
  • Pound will run on 202.54.1.5 port 80
  • It will forward all incoming http requests to internal host 192.168.1.5 and 192.168.1.10 port 80 or 443
  • Pound keeps track of associations between clients and back-end servers

Pound configuration file

  • Under Debian / Ubuntu default file located at /etc/pound/pound.cfg
  • Under FreeBSD it is located at /usr/local/etc/pound.cfg (you need to create this file)
  • Under RHEL / CentOS you need to create file at /etc/pound.cfg

Sample configuration: HTTP Proxy

Forward all incoming request at 202.54.1.5 port 80 request to 192.168.1.5 Apache server running at 8080 port: Open /etc/pound/pound.cfg file: # vi /etc/pound/pound.cfg To translate HTTP requests to a local internal HTTP server, enter (make sure 192.168.1.5 Apache running listing on port 8080):

ListenHTTP
        Address 202.54.1.5
        Port    80
        Service
                 BackEnd
                      Address 192.168.1.5
                      Port    8080
                 End
         End
End

Save and close the file. Restart pound: # /etc/init.d/pound restart

Following example will distribute the all HTTP/HTTPS requests to two Web servers:

ListenHTTP
         Address 202.54.1.5
         Port    80
End

ListenHTTPS
        Address 202.54.1.5
        Port    443
        Cert    "/etc/ssl/local.server.pem"
End
Service
                 BackEnd
                     Address 192.168.1.5
                     Port    80
                 End
                 BackEnd
                     Address 192.168.1.6
                     Port    80
                 End
End

For testing purpose you may generate self signed ssl certificate (/etc/ssl/local.server.pem), by entering the following command: # cd /etc/ssl && openssl req -x509 -newkey rsa:1024 -keyout local.server.pem -out local.server.pem -days 365 -nodes

Pound log file

By default pound log message using syslog: # tail -f /var/log/messages # grep pound /var/log/messages

Sample complete configuration file

## Minimal sample pound.cfg
######################################################################
## global options:
User  "www-data"
Group  "www-data"
#RootJail "/chroot/pound"
## Logging: (goes to syslog by default)
## 0 no logging
## 1 normal
## 2 extended
## 3 Apache-style (common log format)
LogLevel 1
## check backend every X secs:
Alive  30
## use hardware-accelleration card supported by openssl(1):
#SSLEngine "”

######################################################################
## listen, redirect and … to:
# Here is a more complex example: assume your static images (GIF/JPEG) are to be served from  a  single  back-end  192.168.0.10.  In
#       addition,  192.168.0.11  is  to  do  the  hosting for www.myserver.com with URL-based sessions, and 192.168.0.20 (a 1GHz PIII) and
#       192.168.0.21 (800Mhz Duron) are for all other requests (cookie-based sessions).  The logging will be done by the back-end servers.
#       The configuration file may look like this:
             # Main listening ports
             ListenHTTP
                 Address 202.54.1.10
                 Port    80
                 Client  10
             End
             ListenHTTPS
                 Address 202.54.1.10
                 Port    443
                 Cert    “/etc/pound/pound.pem”
                 Client  20
             End

             # Image server
             Service
                 URL “.*.(jpg|gif)”
                 BackEnd
                     Address 192.168.1.10
                     Port    80
                 End
             End
            # Virtual host www.myserver.com
             Service
                 URL         “.*sessid=.*”
                 HeadRequire “Host:.*www.nixcraft.com.*”
                 BackEnd
                     Address 192.168.1.11
                     Port    80
                 End
                 Session
                     Type    PARM
                     ID      “sessid”
                     TTL     120
                 End
             End

             # Everybody else
             Service
                 BackEnd
                     Address 192.168.1.20
                     Port    80
                     Priority 5
                 End
                 BackEnd
                     Address 192.168.1.21
                     Port    80
                     Priority 4
                 End
                 Session
                     Type    COOKIE
                     ID      “userid”
                     TTL     180
                 End
             End

Suggested readings:

=> Pound project => Man pages : pound and poundctl

Discussion on This FAQ

  1. `ariel Says:

    Nice !!! a few weeks ago i was googling for something like this for hours !!!

  2. vivek Says:

    Pound is simple and very nice. Many large site such as wordpress.com uses pound.

  3. Calomel Says:

    I would highly suggest pound or lighttpd as a reverse proxy. As of version 2.4e, Pound is extremely fast and stable. Lighttpd did have some problems in the past and most of those have been fixed. Memeory managment has been greatly improved. I have to agree about the documentation, but there are examples like the following to help everyone out:

    Pound Reverse Proxy “how “to” http://calomel.org/pound.html

    Light webserver “how to” http://calomel.org/lighttpd.html

Linux List All Outdated Packages Which Could be Updated and Applied to System

Q. How can I know what packages are available for binary update under Fedora / RHEL / CentOS Linux version 5 server? How do I list all outdated packages? How do I apply update / patches to system? A. CentOS / RHEL / Fedora Linux version 5 and above supports yum command (yum is an interactive, automated update program which can be used for maintaining systems using rpm). It can list all packages which could be updated from a shell prompt.

First, Login as the root user

Type the following command at shell prompt to list all outdated packages: # yum list updates Output:

Loading "installonlyn" plugin
Loading "rhnplugin" plugin
Setting up repositories
rhel-x86_64-server-vt-5   100% |=========================| 1.2 kB    00:00
rhel-x86_64-server-5      100% |=========================| 1.2 kB    00:00
Reading repository metadata in from local files
Updated Packages
tzdata.noarch                            2007k-1.el5            rhel-x86_64-serv

You can also try to locate specific packages: # yum list updates package-name # yum list updates "*apache*" # yum list updates "regex" To updated packages, enter: # yum update

A note about RHEL version <= 4.x

RHEL version 4.0 and below uses up2date command. It has -l option to show you what package updates are available for download and installing the same. # up2date -l To check for and update all RPM(S), enter: # up2date -u

How to: Snoop / View Other Linux Shell User Typescript of Terminal Session

You could also use screen. Start a screen session with a socket name by using “screen -S student” then everyone can attach the screen with “screen -x student” and everyone with it attached can utilize the session. Then “screen -list” with help if you forget which sessions are detached.

Shell Scripting: Convert Uppercase to Lowercase

Q. How do I convert uppercase words to lowercase or vise versa under BASH shell? I’ve a small shell script and I’d like to convert all incoming user input to lowercase using a shell script. A. Use tr command to convert all incoming text / words / variable data from upper to lower case or vise versa (translate all uppercase characters to lowercase).

Convert all text file data from upper to lowercase:

Type the following command at shell: $ tr '[:upper:]' '[:lower:]' <> output.txt

Convert variable data from upper to lowercase:

$ echo $VAR_NAME | tr '[:upper:]' '[:lower:]' $ echo $VAR_NAME | tr '[:lower:]' '[:upper:]'

Saturday, March 8, 2008

How do I add jobs to cron under Linux or UNIX oses?

Q. How do I add cron job under Linux or UNIX like operating system?

A. Cron job are used to schedule commands to be executed periodically i.e. to setup commands which will repeatedly run at a set time, you can use the cron jobs.

crontab is the command used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

To edit your crontab file, type the following command: $ crontab -e

Syntax of crontab

Your cron job looks like as follows: 1 2 3 4 5 /path/to/command arg1 arg2

Where,

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])
  • /path/to/command - Script or command name to schedule

Same above five fields structure can be easily remembered with following diagram:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Example(s) If you wished to have a script named /root/backup.sh run every day at 3am, my crontab entry would look like as follows: (a) Install your cronjob:# crontab -e(b)Append following entry:0 3 * * * /root/backup.shRun five minutes after midnight, every day:5 0 * * * /path/to/commandRun at 2:15pm on the first of every month:15 14 1 * * /path/to/commandRun at 10 pm on weekdays: 0 22 * * 1-5 /path/to/command Run 23 minutes after midnigbt, 2am, 4am …, everyday:23 0-23/2 * * * /path/to/commandRun at 5 after 4 every sunday:5 4 * * sun /path/to/command

Use of operators

An operator allows you to specifying multiple values in a field. There are three operators:

  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
  2. The comma (,) : This operator specifies a list of values, for example: “1,5,10,15,20, 25″.
  3. The dash (-) : This operator specifies a range of values, for example: “5-15″ days , which is equivalent to typing “5,6,7,8,9,….,13,14,15″ using the comma operator.

How do I disabling Email output?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:0 3 * * * /root/backup.sh >/dev/null 2>&1To mail output to particluer email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:MAILTO="vivek@nixcraft.in" 0 3 * * * /root/backup.sh >/dev/null 2>&1

Task:To list your crontab jobs use the command

Type the following command:# crontab -lTo remove or erase all crontab jobs use the command:# crontab -e

Use special string to save time

Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.

Special string Meaning
@reboot Run once, at startup.
@yearly Run once a year, “0 0 1 1 *”.
@annually (same as @yearly)
@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)
@hourly Run once an hour, “0 * * * *”.

Run ntpdate every hour: @hourly /path/to/ntpdate Make a backup everyday: @daily /path/to/backup/script.sh

Friday, March 7, 2008

Linux Shell Scripting Tutorial v1.05r3 - A Beginner's handbook

Check this cool link for Shell Scripting http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/lsst/

Is There a UNIX / Linux unerase / undelete Command?

Q. Is There a UNIX / Linux unerase or undelete command? How do I undelete files under a UNIX / Linux system? A.. Short answer - no.

There is no “unerase” or “undelete” command in Linux / *BSD / Unix like operating system such as AIX or HP-UX . The best solution is to restore file from a backup. You can also use a data recovery tool but there is no guaranty you will get back the data. Always use following method to avoid problems: => Make regular backups and file system snapshots

=> Never ever login as root for non admin related tasks

=> Always use a regular user account for all normal tasks

=> Alias rm / mv / cp command as rm -i / mv -i alias cp='cp -i' alias mv='mv -i' alias rm='rm -i'

=> Make important file copy before editing

=> Use RAID 6 or above hardware card as additional protection for file server

=> Keep files safe from accidental overwriting with noclobber under BASH shell

=> Make a Linux File unchangeable ( unalterable ) so that no one can modify it - including root user

Difference between Linux and UNIX

Q. What is the difference between Linux and UNIX?

A. UNIX is copyrighted name Only big companies are allowed to use the UNIX copyright and name, so IBM AIX and Sun Solaris and HP-UX all are UNIX. The Open Group holds the UNIX trademark in trust for the industry, and manages the UNIX trademark licensing program.

Linux is UNIX clone

But if you consider Portable Operating System Interface (POSIX) standards then Linux can be considered as UNIX. To quote from Official Linux kernel README file: Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. It aims towards POSIX compliance.

Linux is just kernel

Linux is just kernel. Linux distribution includes GUI system, installation and management tools, compilers, editors etc. Linux distribution makes it

Most UNIX oses considered as compete operating system.

As I said earlier Linux is just kernel with Linux distribution makes it complete usable os. Most UNIX oses comes with A-Z programs such as editor, compilers etc. For example FreeBSD comes with A-Z programs.

License and cost

Linux is Free (as in beer [freedom]). You will see best community support around. Many UNIX oses are not free (but this is changing fast, for example OpenSolaris/Solaris UNIX).

User-friendly

Linux is considered as most user friendly UNIX like os. It makes easy to install sound card, flash players, and other desktop goodies.

End user perspective

The differences are not that big for the average end user.

System administrator perspective

Again, the differences are not that big for the system administrator. However, you may notice difference while performing following operations:

  1. Installation procedure
  2. Hardware Device names
  3. Admin commands or utilities

Following documents or URL should help anyone to get more idea:

How to make a Linux File unchangeable ( unalterable ) so that no one can modify it

Q. How do I write protect file under Linux so that no one can modify it?

A. You need to use chattr command, which changes the file attributes on a Linux second extended file system. The chattr command supports various attributes.

A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute in other words you make a file unchangeable or unalterable.

For example if you want file /data/financial.txt unchangeable by anyone on your system, type the following command (login as the root user): # chattr +i /data/financial.txt Now no one can delete or modify file /data/financial.txt. To reset back permission, type the following command: # chattr -i /data/financial.txt Use lsattr command to lists the file attributes on a second extended file system. It is use to see attributes set by chattr command. # lsattr financial.txt Output:

----i------------ financial.txt

Thursday, March 6, 2008

ping all hosts on the LAN

Today i got a code by which u will get to know which all machines are up in a particular network....

$ for ip in $(seq 1 254); do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.1.$ip UP" || : ; done Output:

192.168.1.1 UP
192.168.1.1 UP
192.168.1.2 UP
192.168.1.5 UP
......
...
..
192.168.1.254 UP