Sunday, August 15, 2010

Cron Task


Configuring a Cron Task

The main configuration file for cron, /etc/crontab, contains the following lines: 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly


The first four lines are variables used to configure the environment in which the cron tasks are run. The value of theSHELL variable tells the system which shell environment to use (in this example the bash shell), and the PATHvariable defines the path used to execute commands. The output of the cron tasks are emailed to the username defined with the MAILTO variable. If the MAILTO variable is defined as an empty string (MAILTO=""), email will not be sent (sendmail on ESX is not installed by default). The HOME variable can be used to set the home directory to use when executing commands or scripts. 
Each line in the /etc/crontab file has the format: 


minute   hour   day   month   dayofweek   command
  • minute — any integer from 0 to 59
  • hour — any integer from 0 to 23
  • day — any integer from 1 to 31 (must be a valid day if a month is specified)
  • month — any integer from 1 to 12 (or the short name of the month such as jan, feb, and so on)
  • dayofweek — any integer from 0 to 7 where 0 or 7 represents Sunday (or the short name of the week such as sun, mon, and so on)
  • command — the command to execute. The command can either be a command such as ls /proc >> /tmp/proc or the command to execute a custom script that you wrote.
For any of the above values, an asterisk (*) can be used to specify all valid values. For example, an asterisk for the month value means execute the command every month within the constraints of the other values. 
A hyphen (-) between integers specifies a range of integers. For example, 1-4 means the integers 1, 2, 3, and 4. 
A list of values separated by commas (,) specifies a list. For example, 3, 4, 6, 8 indicates those four specific integers. 
The forward slash (/) can be used to specify step values. The value of an integer can be skipped within a range by following the range with /<integer>. For example, 0-59/2 can be used to define every other minute in the minute field. Step values can also be used with an asterisk. For instance, the value */3 can be used in the month field to run the task every third month. 
Any lines that begin with a hash mark (#) are comments and are not processed. 
Examples of crontabs
# record the memory usage of the system every monday
# at 3:30AM in the file /tmp/meminfo
30 3 * * mon cat /proc/meminfo >> /tmp/meminfo
# run custom script the first day of every month at 4:10AM
10 4 1 * * /root/scripts/backup.sh
As you can see from the /etc/crontab file, it uses the run-parts script to execute the scripts in the /etc/cron.hourly,/etc/cron.daily/etc/cron.weekly, and /etc/cron.monthly files on an hourly, daily, weekly, or monthly basis respectively. The files in these directory should be shell scripts. 
If a cron tasks needs to be executed on a schedule other than hourly, daily, weekly, or monthly, it can be added to the /etc/cron.d directory. All files in this directory use the same syntax as /etc/crontab
The cron daemon checks the etc/crontab file, the etc/cron.d/ directory, and the /var/spool/cron directory every minute for any changes. If any changes are found, they are loaded into memory. Thus, the daemon does not need to be restarted if a crontab file is changed. 
Users other than root can configure cron tasks by using the crontab utility. All user-defined crontabs are stored in the/var/spool/cron directory and are executed using the usernames of the users that created them. To create a crontab as a user, login as that user and type the command crontab -e to edit the user's crontab using the editor specified by the VISUAL or EDITOR environment variable. The file uses the same format as /etc/crontab. When the changes to the crontab are saved, the crontab is stored according to username and written to the file /var/spool/cron/username

Starting and Stopping the Service

To start the cron service, use the command /sbin/service crond start. To stop the service, use the command/sbin/service crond stop. It is recommended that you start the service at boot time.

Expand Virtual disk (VMDK) in VMware

How to Grow a virtual disk in a VMWare virtual machine

A VMDK file can be grown while no virtual machine is using it. Growing the VMDK only makes the virtual harddrive bigger - filesystem within the VMDK must still to be grown with other methods. 

On ESX Server:
          vmkfstools -X Gb  filename.vmdk
On ESX 3.5, you can also edit the VM settings and edit the harddrive when the VM is not running.

Note:  On ESX the filename.vmdk file is just a  file containing metainformation and "filename-flat.vmdk" is the actual data file. 

However, vmkfstools operations are used on the metafile



On VMware Server Workstation and VMware Fusion:
           vmware-vdiskmanager -x Gb filename.vmdk



For Example:


    If growing an existing vmdk file named "server1.vmdk" and it is to be grown so it's new size is 20GB, the command would be:
On ESX Server:


          vmkfstools -X 20GB server1.vmdk


What is KVM on Linux?


Kernel Based Virtual Machine

KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU although work is underway to get the required changes upstream.
Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.
The kernel component of KVM is included in mainline Linux, as of 2.6.20.
KVM is open source software.

Linux Backup Tips

There is option in linux itself to take the image backup in multiple ways, please check as follows

Backup Methods
1. Taking a snapshot of hda to hdb
dd if=/dev/hda of=/dev/hdb

2. Taking hda as the image file
dd if=/dev/hda of=/path/to/image

3. Taking hda as the zip file
dd if=/dev/hdx | gzip > /path/to/image.gz

MBR backup
1. To take the MBR backup
dd if=/dev/hda(1) of=/path/to/image count=1 bs=512

Restore Methods
1. To restore the Backup from image file  
dd if=/path/to/image of=/dev/hda

2. To restore the backup from the ZIP file
gzip -dc /path/to/image.gz | dd of=/dev/hda


MBR restore
1. To restore the MBR image backup
dd if=/path/to/image of=/dev/hda(1)
Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.   

Differences: VMWARE Player, VMWARE Workstation and ESX Server


I Listed the differences between VMWARE player, VMWARE Workstation/server and VMWARE ESX Server. I have provided the information as well as i know. If anyone having questions, Please comment . Please correct me  if i missed something. 

VMWare Player
VMware Workstation & Server
VMware ESX Server
With VMware Player you can only run pre-created Virtual Machine, either you create it with VMware Workstation/Server or you download it from VMware Virtual Appliance Marketplace 
You can create, Play, Modify Virtual Machines
You can create, Play, Modify Virtual Machines
You cannot create or modify a virtual Machine using VMPlayer. You can run only
You can create, modify any number virtual machines up to your need
You can create, modify monitor virtual machines using VSphere client
Its free of cost
Licensed
Licensed
Need to be installed on OS Desktops like Windows, Linux, MAC
Need to be installed on OS Desktops  like Windows, Linux, MAC
This will be installed as OS. Other Operating systems will be hosted here as virtual machine. VMware ESX server itself is an OS. On top of it, other OS like Windows Server, Linux will be installed
Desktop Use, for development, testing, QA Etc..
Desktop Use, for development, testing, QA Etc..
Used for production servers use
No extra features
Having features snapshots, screen recordings, cloning etc.
Having several features like physical to virtual convertor etc.
NA
CPU and Memory support up to the editions like Workstation or server
CPU and Memory support up to licensing. (Min 2 CPU’s and 8GB RAM)

Reset your Windows password through Command prompt

Procedure to reset your password is given below:-

1) To display the users present in the computer

C:\>net user

User accounts for \\

-------------------------------------------------------------------------------
ASPNET                   Administrator
testuser
The command completed successfully.
==============================================================
2) To display the user details:-

C:\>net user testuser
User name                    testuser
Full Name                    testuser
Comment
User's comment
Country code                 000 (System Default)
Account active               Yes
Account expires              Never

Password last set            3/19/2010 2:15 PM
Password expires             Never
Password changeable          3/19/2010 2:15 PM
Password required            Yes
User may change password     Yes

Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   Never

Logon hours allowed          All

Local Group Memberships      *Users
Global Group memberships     *None
The command completed successfully.
=======================================================
3) To reset the password

C:\>net user testuser *
Type a password for the user:******
Retype the password to confirm:******
The command completed successfully.

Questions With Answers

1. What is the command to see if any particular process is running in UNIX?

ps -ef | grep

2. How do you see the version details on a Linux machine?

1. uname -a - This will give you kernel and other details
2. cat /etc/redhat-release - This will give you the OS Version release  details 

3. Where are the configuration files stored in linux file system, which
directory?

/etc

4. Which file stores the password details of Users in linux?

 /etc/passwd 
 /etc/shadow  -- Optional

5. What is the Command used to see the access permissions for a directory?

ls -ld

6. Command to change permissions of a file allowing all execute permissions?

chmod u+x,g+x,o+x

or

chmod 555  


7. What is the command used to see the environment variables on UNIX?

env

Basic Networking questions


1. How do the open/used ports on your system?

Try /etc/services* file

What is MD5/MD5SUM?

The MD5 checksum for a file is a 128-bit value, something like a fingerprint of the file. There is a very small possibility of getting two identical checksums of two different files. This feature can be useful both for comparing the files and their integrity control.

Let us imagine a situation that will help you to understand how the checksum works.

Alice and Bob have two similar huge files. How do we know that they are different without sending them to each other? We simply have to calculate the checksums of these files and compare them.

The RFC 1321 describes MD5 checksum (MD5 message-digest) as:

The algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.