linux server – cron , crontab

Cron

Cron is a daemon that executes scheduled commands. Cron is started automatically from /etc/init.d Cron searches its spool area (/var/spool/cron/crontabs) for crontab files. It load crontab files on memory to run.

cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon.

 

We cannot access crontab files directly , it will be accessible via crontab.

Cron also reads /etc/crontab, which is in a slightly different format. Additionally, cron reads the files in /etc/cron.d.

Cron runs every minute and check for whether any job has to run or not. It can modify automatically so we do not nee dto restart server after making changes to crontab.

Crontab

Crontab is the program which contains lists of job to be run. Crom daemon looks that list and run the job as per scheduled.

 

crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

 

Crontab format:-

Commands are executed by cron when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time.

 

Crontab syntax :
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

 

A field may be an asterisk (*), which always stands for “first-last”.

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an “hours” entry specifies execution at hours 8, 9, 10 and 11.

if you want to say “every two hours”, just use “*/2”.

example

minutes , hours, day of month , month , day of week, command(or path of shell script)

An example of crontab format with commented fields is as follows:

# Minute   Hour   Day of Month       Month          Day of Week        Command    
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)                
    0        2          12             *               0,6           /usr/bin/find

reference:

 

http://www.pantz.org/software/cron/croninfo.html

http://www.adminschoice.com/crontab-quick-reference/

example of crontab:-

[anand@server001 ~]$ crontab -l
#*/5 * * * * /home/anand/scripts/apacheMon.sh
*/5 * * * * /home/anand/scripts/mysqldMon.sh
#*/5 * * * * /home/anand/scripts/apacheaccesslog.sh
*/5 * * * * /home/anand/scripts/apacheerrorlog.sh
*/10 * * * * /home/anand/scripts/cpuidle.sh
*/10 * * * * /home/anand/scripts/dbstat.sh
*/5 * * * * /home/anand/scripts/diskalert.sh
00 00 * * * /home/anand/scripts/deadlock.sh

[anand@server001 ~]$ more /home/anand/scripts/deadlock.sh
#!/bin/sh
#***********************************************************************
#Script to check deadlock
#Created by Anand
#***********************************************************************
Maillist=”anand.kumar@test.com”
host=`hostname`
File_Location=”/apps/www/anand/log”
#printf ‘file location’$File_Location
#dateformat=`date +%d-%m-%Y`
dateformat=`date +%d-%m-%Y -d “1 day ago”`
#printf ‘date format’$dateformat
FILE=$File_Location/$dateformat\_DbFailure.txt
if [ -f $FILE ];
then
Count=`grep -i “Invalid query: Deadlock found when trying to get lock;” $FILE | wc -l`
if [ $Count -gt 0 ]
then
echo -e “Invalid query: Deadlock found on Server 001, Please manually run the insert commands.\n Number of deadlock found:$Count.\n Path of insert query is: $FILE” > /tmp/Error
mail -s “Critical!! – Deadlock while insertion in server001” $Maillist < /tmp/Error
fi
fi
[anand@server001 ~]$ vi /home/anand/scripts/deadlock.sh

To edit the shell script.

How to Install SQuirrel SQL Client on windows

                                                  How to install Squirrel SQL Client

STEP 1. Hit the URL:- http://www.squirrelsql.org/#installation

 

Click on the link on the page

Install jars of SQuirreL 3.3.0 for Windows/Linux/others

After clicking the above link , you are able to download “squirrel-sql-3.3.0-install.jar”.

Save “squirrel-sql-3.3.0-install.jar” file in C Drive.

 

STEP 2:- Open Command line (CLI) [start->run->cmd and press ENTER]

C:\Documents and Settings\Kumar>cd ../..

C:\>

Now , type java -jar squirrel-sql-3.3.0-install.jar at CLI and press ENTER

It will open SQuirrel software installation package. Just click on next , next and install the software.

STEP 3:- Open Squirrel software and click on Drivers tab

 

STEP 4:- To enable Oracle Thin Driver , you have to download ojdbc14.jar and add this jar file in “Squirrel\lib” folder.

 

Download link: http://www.findjar.com/jar/mule/dependencies/maven1/oracle-jdbc/jars/ojdbc14.jar.html

 

Restart the Squirrel software, where you can able to see that Oracle Thin Driver is enabled.

 

 

STEP 5:-

Click on Aliases tab , click on +(add) button to add new database.

In ADD Alias , provide NAME for Database ,

Select Oracle Thin Driver  in Driver drop down box.

Provide the URL , Username and password.

URL should be like:-

jdbc:oracle:thin:@101.101.198.134:1621:PRODDB

 

 

Click on TEST button , if all details are correct then it should show below mentioned  message on screen.

Drupal termnology

Basically, there are 5 main layers in Drupal where information flows,

  1. Data (Node, ETC)
  2. Modules
  3. Blocks and Menus
  4. User Permissions
  5. Template

 

Data
Base of the system is collection of Nodes. – the data pool

Modules
These are functional plugins that are either part of the Drupal core (they ship with Drupal) or they are contributed items that have been created by members of the Drupal community.

Blocks and Menus
This is the next layer where we find blocks and menus. Blocks often provide the output from a module or can be created to display whatever you want, and then can be placed in various spots in your template (theme) layout. Blocks can be configured to output in various ways, as well as only showing on certain defined pages, or only for certain defined users.

User Permissions
Here is the next layer where settings are configured to determine what different kinds of users are allow to work and see.

Template
This is mainly the site theme or the skin. This is made up predominantly of XHTML and CSS, with some PHP variables intermixed

Understanding this flow of information is very important if you are facing A Drupal project targeted interview as the interviewer might test your overall knowledge  of  Drupal CMS by asking this sort of questions.

 

 

 

 

 

 

What is taxonomy in drupal?

We can define any number of vocabularies (category types) and terms (categories)
e.g.
Controversial Content: (vocabulary)
– violence (term)
– adult content (term)

Genre (Vocabulary)
– Comedy (term)
– Romance (term)

We can config which content types are compatible with which vocabulary and which nodes are belong to which terms.

Some important drupal modules: Views, CCK, Path auto, FCK Editor, User points, Flags, Panels, Image cache

 

What is a block?

Block is a section in a page (recent posts, news, vote to something, login box, navigation), which is movable to regions (header, footer, content top etc) in a page. Blocks can be configured to show/hide only to certain type of user roles, url patterns or some other advanced criteria. (Content area is not a block)

What is a node in Drupal?

A node is a unit of content. It has a type. Page, News or as Testimonial.

Which are the core required modules in drupal 6.x ?

1. Block — Controls the boxes that are displayed around the main content.
2. Filter — Handles the filtering of content in preparation for display.
3. Node — Allows content to be submitted to the site and displayed on pages.
4. System — Handles general site configuration for administrators.
5. User — Manages the user registration and login system.

 

 

 

 

 

Drupal Modules

These key modules are some of the most important ones to add no matter what type of site you want to build with Drupal.

We need  TOKEN module http://drupal.org/project/token

 

Download FCKEDitor from sourcrforge and unzip it.

Place this unzip FCKEditor folder inside sites/aa/modules/FCKEditor .

There will be another folder as FCKEditor in FCKedior module folder ,copy the unzip from above link and copy here .

  • IMCE for uploading images to insert into posts
  • Poor Mans Cron for easy execution of the Drupal cron file

What is VIEW Module ?

VIEW is a powerful query builder for Drupal that allows you to fetch and present lists and tables of content (posts/nodes) to the user in ways that are tailored to your site and your content.

The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Views can be used to generate reports, create summaries, and display collections of images and other content.

 

You need Views if:

  • You like the default front page view, but you find you want to sort it differently.
  • You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
  • You use /tracker, but you want to restrict it to posts of a certain type.
  • You like the idea of the ‘article’ module, but it doesn’t display articles the way you like.
  • You want a way to display a block with the 5 most recent posts of some particular type.
  • You want to provide ‘unread forum posts’.
  • You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of “Month, YYYY (X)” where X is the number of posts that month, and displays them in a block. The links lead to a simple list of posts for that month.

 

jQuery Tutorial Demo: Select All Checkboxes & validate Form

This tutorial will teach you to add validation using JQUERY validate.js file and get multiple checkbox valu using JQUERY jquery.js file.

These two js files jquery.js , jquery.validate.js is very useful when user wants to do validation of form on client side server .

Here the attached code.just download these two js files from JQUERY site and embedd in below code and run the file on browser .

<html>
<head>
<title>jQuery Tutorial Demo: Select All Checkboxes</title>
<script type=”text/javascript” src=”/jquery/jquery.js”></script>
<script type=”text/javascript” src=”/jquery/jquery.validate.js”></script>
<style type=”text/css”>body{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px}
h1, h2{font-size:20px;}</style>

<script type=”text/javascript”>
$(document).ready(function()
{
$(“#paradigm_all”).click(function()
{
var checked_status = this.checked;
$(“input[name=paradigm[]]”).each(function()
{
this.checked = checked_status;
});
});
});

//initiate validator on load
$(function() {
// validate contact form on keyup and submit
$(“#userForm”).validate({
//set the rules for the field names
rules: {
first_name: {
required: true,
minlength: 2
},
last_name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
company: {
required: true,
minlength: 2
},
},
//set messages to appear inline
messages: {
first_name: “*Please enter First Name”,
last_name: “*Please enter Last Name”,
email: “*Please enter a valid Email address”,
company: “*Please enter Company Name”
}
});
});

</script>
<style type=”text/css”>
.error {
color: red;
font: 12pt verdana;
padding-left: 10px
}
</style>
</head>
<body>

<h1>jQuery Tutorial: Multiple Checkbox values & Validation of FORM </h1>
<p>You will learn how to select/deselect all checkbox and get all the values of checked box.<br/>
This will also teach you to validate your FORM using JQUERY validate.js.
</p>
<br/><br/>
<?php
if(isset($_POST) && !empty($_POST))
{
var_dump($_POST);
}
?>
<form name=”myform” action =”#” id=”userForm” method=’post’ enctype=’multipart/form-data’>
<label for=”first_name”>First Name</label><br />
<input name=”first_name” id=”first_name” /><br />
<label for=”last_name”>Last Name</label><br />
<input name=”last_name” id=”last_name” /><br />
<label for=”email”>Email address/Username</label><br />
<input name=”email” id=”email” /><br />
<label for=”company”>Company</label><br />
<input name=”company” id=”company” /><br /><br />
<label>Role</label><br/>
<input type=”checkbox” name=”paradigm[]” value=”Imperative”>Imperative<br/>
<input type=”checkbox” name=”paradigm[]” value=”Object-Oriented”>Object-Oriented<br/>
<input type=”checkbox” name=”paradigm[]” value=”Functional”>Functional<br/>
<input type=”checkbox” id=”paradigm_all”>Select All<br><br />
<input type=”submit”  value=”save” />

</body>
</html>

Drupal 6 Installation on windows

DRUPAL INSTALLATION

1.UNZIP  Drupal-6.15 and rename folder drupal-6.1.5 to drupal and copy that in your server webroot
I am using XAMPP , so I kept this “drupal”  folder in “htdocs” folder
Start your Xampp server.
On browser , type:-
http://localhost/drupal
it will show this page as in screenshot
2.Follow drupal instructions
Choose language to English

1

3. After that you will get this screen

2

3

4.You will get screen like below and enter your DB name and all , after that click on ” SAVE AND CONTIUNE “ button

4

5. After that you will see screen as shown below .
This prompt error message because we don’t have “drupal_team”  database in MYSQL DB

5

 First create “drupal_team” db in MYSQL database
As  shown in screenshot

6

After creating DB name in MYSQL

6.Goto drupal installation browser
 
NOTE:- if u want then put prefix for your tables in “drupal_team” database. Its optional
See screenshot:-

7

7. after that we will see screen as shown and fill appropriate data .

8

9
10

8. AT last you will see screen as shown below , SMTP error will come but its just for mailing functionality which you can resolve in php.ini file.

11

JQuery Table Sorter Plugin

TableSorter plugin is used to do single column sorting as well as multiple column sorting without refreshing a whole page .

Here is a small Example to show  how Tablesorter plugin works.

STEP 1:-
download jquery.js and jquery-tablesorter.js file

STEP 2:- Embedd that js file into your source code or in your webpage.

Between  <HEAD></HEAD> tag , copy these lines

<script type=”text/javascript” src=”/path/to/jquery.js”></script>
<script type=”text/javascript” src=”/path/to/jquery.tablesorter.js”></script>

NOTE:- provide jquery.js and jquery-tablesorter.js path in src attribute

STEP 3:- Between  <BODY></BODY> tag, copy these lines and paste


<h1><u>Multiple Column Sorting  Example</u></h1>

<table  cellpadding=”3″ cellspacing=”1″  width=”100%”  id=”myTable”>
<thead >
<tr><th  width=”60″ >Name</th>
<th width=”60″>Task</th>
<th  width=”60″>Cell No.</th>
<th  width=”60″>Start Date</th>
<th  width=”60″>End Date</th>
<th  width=”60″>Completed By</th>
</tr>
</thead>
<tbody>
<tr><td>
Anand
</td>
<td>
PHP
</td>
<td>
111-222-3333
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
ak60991
</td>
</tr>
<tr>
<td>
Vishal
</td>
<td>
Coldfusion
</td>
<td>
111-222-3334
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
vu60998
</td>

</tr>
<tr>
<td>
Anand
</td>
<td>
Coldfusion
</td>
<td>
111-222-3334
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
ak60991
</td>

</tr>
<tr>
<td>
Himadri
</td>
<td>
Coldfusion
</td>
<td>
111-222-3334
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
hr60001
</td>

</tr>

<tr>
<td>
Gaurav
</td>
<td>
Coldfusion
</td>
<td>
111-222-3336
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
gt56001
</td>
</tr>
<tr>
<td>
Himadri
</td>
<td>
Oracle
</td>
<td>
111-222-3336
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
gt56001
</td>
</tr>
<tr>
<td>
Vishal
</td>
<td>
Oracle
</td>
<td>
111-222-3336
</td>
<td>
11/16/2009
</td>
<td>
11/23/2009</td>
<td>
vu60998
</td>
</tr>

</tbody>
</table>
<p><span><font color=”#990000″ size=”+1″><b>NOTE:</b></font></span> hold  shift key and click on  multiple headers/columns to do multiple column sorting!</p>


STEP 4:-Between <HEAD></HEAD> tag , copy and paste these lines

<script type=”text/javascript”>
<!–jQuery.noConflict();–>
var $j = jQuery.noConflict();

$j (document).ready(function()     {
//$j (“#myTable”).tablesorter({widgets: [‘zebra’]});

$j (“#myTable”).tablesorter();
}
);
</script>


Description:

this particular script will apply tablesorter() function of JQuery to table which has id ‘myTable’


STEP 5:- Add CSS style sheet into your code .

Copy and paste these lines between <HEAD></HEAD> tag


<style type=”text/css”>
.sort{font-size:9px;}

table.tablesorter .header {
background-image: url(“/path/to/bg.png”);
background-repeat: no-repeat;
padding-left: 30px;
padding-top: 8px;
width:auto;
}

table.tablesorter th.no_sort {
background-image: url(“/path/to/header.PNG”);
}
table.tablesorter .headerSortUp {
background-image: url(“/path/to/asc.png”);
background-repeat: no-repeat;
}
table.tablesorter .headerSortDown {
background-image: url(“/path/to/desc.png”);
background-repeat: no-repeat;
}
table.tablesorter .even {
background-color: #9999CC;
}
table.tablesorter .odd {
background-color: #FFFFFF;
}
</style>


Save your code and run it . Congrats you have implemented sorting on your table .

Screenshot is added


FEW Tips: open JQuery-tablesorter.js file,

you will see  some default values , you can change these values based on your requirements.i have commented on some parameters in below code .

this.defaults = {
cssHeader: “header”,// css header class
cssAsc: “headerSortUp”, // css headerSortUp class
cssDesc: “headerSortDown”, // css headerSortDown class
sortInitialOrder: “asc”, // you can change it based on how you want initial sorting
sortMultiSortKey: “shiftKey”,// here you can use CTRL key also
sortForce: null,
sortAppend: null,
textExtraction: “simple”,
parsers: {},
widgets: [‘zebra’],
widgetZebra: {css: [“even”,”odd”]},// css even ,odd class
// below commented code will disable sorting on first and second column
//headers: {0: { sorter: false}, 1: {sorter: false}},
headers: {},
widthFixed: false,
cancelSelection: true,
sortList: [],
headerList: [],
dateFormat: “us”,
decimal: ‘.’,
debug: false
};


LIGHTBOX Tutorial

Lightbox is a useful JavaScript, which allows you to watch photos in a semi-transparent overlay to your site. When you click on a link, the picture is shown above the content of your page, which frees you of limitations like columns.

This tutorial is about setting up Lightbox to work on your page.

STEP 1: download lightbox.js , lightbox.css ,prototype.js,scriptaculous.js,effects.js and builder.js

 

STEP 2: Create a folder “launchpad” and “js” , “css” and “image” sub folder inside “launchpad” folder.

NOTE:- you can create a folder structure according to your wish also .

In “js” folder , keep all js files like:

lightbox.js ,prototype.js,scriptaculous.js,effects.js and builder.js

In “css” folder . keep lightbox.css file.

In “images” folder , keep all your images that you want to be displayed as photo gallery.

STEP 3: keep “lauchpad” folder inside C:\ drive

NOTE:- you can put this folder anywhere according to your wish but then you have to take care of Path of these folder.

STEP 4: Create lightbox.html page (you can rename your filename also.)

source code of lightbox.html :-

 

<html>
<head>
<title> Lightbox Example</title>
<link rel=”stylesheet” href=”c:/lightbox/css/lightbox.css” type=”text/css” media=”screen” />

// Lightbox.css :- for lightbox layout designing
<br/>
<script src=”c:/lightbox/js/prototype.js” type=”text/javascript”></script>
//prototype.js :-This will call to a needed Javascript file, ‘prototype.’ Without prototype, Lightbox WILL NOT function.
<br/>

<script src=”c:/lightbox/js/scriptaculous.js?load=effects,builder” type=”text/javascript”></script>

//scriptaculous.js :- Above statement  Not only  it calls to scriptaculous, but it will also call to effects.js and builder.js. Scriptaculous has a feature that will load the needed JS files with itself, hence the ?load after scriptaculous.js

<br/>

<script src=”c:/lightbox/js/lightbox.js” type=”text/javascript”></script>
//Lightbox.js

</head>
<body>
<h1>Light Box Example</h1>
<br/><br/>
<a href=”c:/lightbox/images/a.jpg” rel=”lightbox” title=”Gallery”>What is it?</a><br/><br/>

// The beauty of Lightbox is that you only need to call to it in link attributes, and not image attributes. <br/>
// rel=”lightbox” tells the webserver that the relation of this link is Lightbox, so, it will link Lightbox.js and all other JS files to the link. <br/>
// Title is optional, it will be displayed below the image<br/>
// Now, we’ll link some images together, commented code will be after so you understand.<br/>

<br/><br/>

<a href=”c:/lightbox/images/a.jpg” rel=”lightbox[outdoors]”>Gallery 1</a><br/>
<a href=”c:/lightbox/images/b.jpg” rel=”lightbox[outdoors]”>Gallery 2</a><br/>
<a href=”c:/lightbox/images/c.jpg” rel=”lightbox[outdoors]”>Gallery 3</a><br/>
<a href=”c:/lightbox/images/d.jpg” rel=”lightbox[outdoors]”>Gallery 4</a><br/>
<a href=”c:/lightbox/images/e.jpg” rel=”lightbox[outdoors]”>Gallery 5</a><br/>
<br/><br/>
//Everything is the same as above, except that we’ve added within brackets the word ‘outdoors.’ Outdoors links those five images together so that we will get ‘Next’ and/or ‘Previous’ linkings within Lightbox.
</body>
</html>

copy and paste this code into lightbox.html file

NOTE: –

<a href=”c:/lightbox/images/a.jpg” rel=”lightbox[outdoors]”>Gallery 1</a><br/>
<a href=”c:/lightbox/images/b.jpg” rel=”lightbox[outdoors]”>Gallery 2</a><br/>
<a href=”c:/lightbox/images/c.jpg” rel=”lightbox[outdoors]”>Gallery 3</a><br/>
<a href=”c:/lightbox/images/d.jpg” rel=”lightbox[outdoors]”>Gallery 4</a><br/>
<a href=”c:/lightbox/images/e.jpg” rel=”lightbox[outdoors]”>Gallery 5</a><br/>

In the above code ,

you   can rename your image name as well as you can use “n”  number of images that has to be displayed.

suppose , i can add other statement in above code,like this

<a href=”c:/lightbox/images/hello.jpg” rel=”lightbox[outdoors]”>Gallery 6</a>

STEP 5: In lightbox.css,

change  path of images for these attributes

fileLoadingImage:        ‘c:/lightbox/images/loading.gif’,     
 fileBottomNavCloseImage: ‘c:/lightbox/images/closelabel.gif’,

STEP 6: run lightbox.html page and click on  any of links to see lightbox effects .