Archive for December, 2008|Monthly archive page
How to Use the Cron and Crontab commands
How to Use the Cron and Crontab commands
The ‘Cron’ Command
The cron command starts a process that executes commands at specified dates and times. Regularly scheduled commands can be specified according to instructions found in the crontab files in the directory /var/spool/cron/crontabs. Users can submit their own crontab files via the crontab command.
The ‘Crontab’ Command
Crontab copies the specified file or standard input if no file is specified, into a directory that holds all users’ crontabs.
SYNOPSIS:
* crontab [file]
* crontab -e [-u username]
* crontab -r [-u username]
* crontab -l [-u username]The -e option edits a copy of the current users’ crontab file or creates an empty file to edit if crontab does not exist.
The-r option removes a user’s crontab from the crontab directory.
The -l options lists the crontab file for the invoking user.
Setting up a Crontab job
A crontab file consists of lines of six fields each.The fields are separated by spaces or tabs. The first five are integers that specify the following:
1. minute (0-59),
2. hour (0-23),
3. day of the month (1-31),
4. month of the year (1-12),
5. day of the week (0-6 with 0=Sunday).Each of these patterns may be either an asterisk (meaning all valid values) or a list of elements separated by commas. An element is either a number or two numbers separated by a minus sign ( meaning an inclusive range). Notice the time is in 24 hour format, 0 is midnight and 13 is one in the afternoon.
The sixth field of a line in a crontab file is a string to be executed by the shell at the specified times by the first fife fields. A percent character in this field (unless escaped by \) is translated to a newline character. Only the first line (up to a % or end of line) of the command field is executed by the shell. The other lines are made available to the command as standard input.
Any line beginning with a # is a comment and is ignored.
Example
To illustrate, 0 0 1,15 1 would run a command on the first and fifteenth of each month, as well as on every Monday at exactly midnight. To specify days by only one field, the other field should be set to *. The entry, 0 23 * * 1 would run a command only on Mondays at eleven PM.
A minute specification of 0,30 would indicate the job is to be run on the hour and half hour. Likewise, a day of the month entry of 1,15 would initiate execution on the first and fifteenth of the month.
Make sure you include an explicit path to your programs or scripts that you want to run by crontab. Let’s assume we want to execute a Perl program, autoclose.cgi, every day at midnight. Additionally assume the full path to the script is /home/www/yourdirectory/cgi-bin. The full crontab command would be: 0 0 * * * /home/www/yourdirectory/cgi-bin/autoclose.cgi
Execute at midnight, every day of the month, every month of the year, and every day of the week.
If you’re not sure of the full path to your script, go to the directory and issue the command:
pwd
This is the “print working directory” command. The requirement for explicit paths also apply to any “require” library file used in a Perl script.
The line:
0 0 1,15 * 1 /home/www/yourdirectory/cgi-bin/autoclose.cgi
runs the command on the first and fifteeth of each month, as well as on every Monday.
The line:
0 0 * * 1 /home/www/yourdirectory/cgi-bin/autoclose.cgi
runs a the command only on Mondays.
Putting it all together
Creating your first crontab job is a three-part process:
1. Prepare the absolute path to the program or script that you want to run,
2. Create a text file containing a line to schedule the job as described above for crontab fields,
3. Upload the text file to your system cron.When preparing program to run or creating scripts to run remember that crontab jobs are background tasks. There is no terminal attached to a crontab job so there should be no print statements that normally write to the screen. (It is possible to redirect such print statements.) The same consideration hold true for requesting user input.
Let’s assume that we want to run this script:
/home/www/yourdirectory/cgi-bin/autoclose.cgi
Next create a file to hold your crontab instructions. Let’s call it “cron.txt”. Let’s also have our script execute at zero minute every hour. Put the following crontab command line in the text file “cron.txt” and save this file as a text file: 0 * * * * /home/www/yourdirectory/cgi-bin/autoclose.cgi
The last step is uploading the contents of your “cron.txt” file to the system crontab spool area. Enter the following at the system prompt.
crontab cron.txt
Now you are done with this project.
If you would like additional detailed information on crontab, enter the following at your Unix prompt.
man crontab
htaccess Site Redirection Without Parameters
Htaccess Solutions | LAMPdocs: Linux, Apache, MySQL, PHP
htaccess Site Redirection Without Parameters
Sometimes you need to redirect all traffic from one site to another. Very often site structure is different and the need is to send visitors to the main page of the site. This makes Site Redirection tabs of all known panels unusable, as the parameters are being sent to the new site.
Install multiple versions of IE on your PC | IE3 IE4.01 IE5 IE5.5 and IE6
Install multiple versions of IE on your PC | TredoSoft
which, in the end , will conveniently create shortcuts based on your preferences
setup pic2
Important Notes:
* The installer was made to work with Windows XP. With a little bit of hacking it could run on Windows 2000 but this was not tested. See some of the comments below for ways to run Multiple IE on Windows 2000 (page 4).
* The Developer tool bar from Microsoft WILL NOT work in IE6
* Sometimes IE5, IE5.5 and IE6 crash unexpectedly.
break out of frame
block a “break out of frame” script : javascript, IE6+, FF2+, and Safari
1
<script language=”JavaScript” type=”text/javascript”>
function breakout_of_frame()
{
if (top.location != location) {
top.location.href = document.location.href ;
}
}
</script>2
<script language=”JavaScript”>
if(parent.frames.length>=1)
{
window.top.location.href=”index.html”
}
</script>3
<script>
if (parent.frames.length > 0) {
parent.location.href = self.document.location
}
</script>4
<script>
if (window!= top)
top.location.href=location.href
</script>5
if (top!= self) top.location=self.document.location;6
top.location.href
What Regular Expression?
Learn how to write a Regular Expression:
What Regular Expression?
A regular expression is a pattern that can match various text strings, used for validations.Where and when to use Regular Expression?
It can be used in the programming languages which supports or has regular expression class as in built or it supports third party regular expression libraries.Regular expressions can be used to valid different type of data without increase the code with if and case conditions. A number of if conditions can be omitted with single line of regular expression checking.
Benefits of Regular Expression:
The following are benefits (not all included) of use of Regular Expression.
a) # line of code can be reduced.
b) Speed Coding.
c) Easy maintenance (you don’t need to change if validation criteria changes, just check the regular expression string).
d) Easy to understand (you don’t need to understand the programmer logic on large if statements and case statements).Elements of Regular Expression:
Here are the basic elements of regular expression characters/literals, which can be used to build big regular expressions:^ —->Start of a string.
$ —->End of a string.
. —-> Any character (except \n newline)
{…}—-> Explicit quantifier notation.
[...] —->Explicit set of characters to match.
(…) —->Logical grouping of part of an expression.
* —->0 or more of previous expression.
+ —->1 or more of previous expression.
? —->0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string.
\ —->Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below.
\w —-> matches any word character, equivalent to [a-zA-Z0-9]
\W —-> matches any non word character, equivalent to [^a-zA-Z0-9].
\s —-> matches any white space character, equivalent to [\f\n\r\v]
\S—-> matches any non-white space characters, equivalent to [^\f\n\r\v]
\d —-> matches any decimal digits, equivalent to [0-9]
\D—-> matches any non-digit characters, equivalent to [^0-9]\a —-> Matches a bell (alarm) \u0007.
\b —-> Matches a backspace \u0008 if in a [] character class; otherwise, see the note following this table.
\t —->Matches a tab \u0009.
\r —->Matches a carriage return \u000D.
\v —->Matches a vertical tab \u000B.
\f —->Matches a form feed \u000C.
\n —->Matches a new line \u000A.
\e —->Matches an escape \u001B$number —-> Substitutes the last substring matched by group number number (decimal).
${name} —-> Substitutes the last substring matched by a (? ) group.
$ —-> Substitutes a single “$” literal.
$S —-> Substitutes a copy of the entire match itself.
Learn how to write a Regular Expression:—-> Substitutes all the text of the input string before the match.
—-> Substitutes all the text of the input string after the match.
—-> Substitutes the last group captured.
$_ —-> Substitutes the entire input string.(?(expression)yes|no) —-> Matches yes part if expression matches and no part will be ommited.
Simple Example:
Let us start with small example, taking integer values:
When we are talking about integer, it always has fixed series, i.e. 0 to 9 and we will use the same to write this regular expression in steps.a) Regular expression starts with “^”
b) As we are using set of characters to be validated, we can use [].
c) So the expression will become “^[1234567890]”
d) As the series is continues we can go for “-“ which gives us to reduce the length of the expression. It becomes “^[0-9]”
e) This will work only for one digit and to make it to work for n number of digits, we can use “*”, now expression becomes “^[0-9]*”
f) As with the starting ending of the expression should be done with “$”, so the final expression becomes “^[0-9]*$”Note: Double quotes are not part of expression; I used it just to differentiate between the sentences.
Is this the way you need to write:
This is one of the way you can write regular expression and depending on the requirements and personal expertise, regular expression could be compressed much shorter, for example above regular expression could be reduced as.a) Regular expression starts with “^”
b) As we are checking for the digits, there is a special character to check for digits “\d”
c) And digits can follow digits , we use “*”
d) As expression ends with “$”, the final regular expression will become
“^\d*$”Digits can be validated with different ways of regular expressions:
1) ^[1234567890]*$
2) ^[0-9]*$
3) ^\d*$Which one to choose?
Every one of above expressions will work in the same way, choose the way you are comfort, it is always recommended to have a smaller and self expressive and understandable, as these will effect when you write big regular expression.Example on exclude options:
There are many situation which demands us to exclude only certain portion or certain characters,
Eg: a) Take all alpha numeric and special symbols except “&”
b) Take all digits except “7”
then we cannot prepare a big list which includes all instead we use the symbol of all and exclude the characters / symbols which need to be validated.
Eg: “^\w[^&]*$” is the solution to take all alpha numeric and special symbols except “&”.Other Examples:
a) There should not be “1” as first digit,?
^[^1]\d*$ ? this will exclude 1 as first digit.b) There should not be “1” at any place?
^\d[^1]*$ ? this will exclude the 1 at any place in the sequence.Note: Here ^ operator is used not only to start the string but also used to negate the values.
Testing of Regular expression:
There are several ways of testing this
a) You can write a windows based program.
b) You can write a web based application.
c) You can even write a service based application.
Drupal 6 media streaming with Dash Media Player
Drupal 6 media streaming with Dash Media Player | codegobbler.com
Drupal 6 media streaming with Dash Media Player
Posted by tom on 20th Sep 2008
in* drupal
* streamingSeveral weeks ago I took a fairly in-depth look at the current video streaming options available for Drupal 6. Shortly after I published the article, a new product entered the market – Dash Media Player. Dash Player is the creation of Travis Tidwell from TMT Digital, also the developer of the FlashVideo module for Drupal.
From the project’s home page…
IP Tracing and IP Tracking
122.161.54.239 – IP location, ISP and more info.
IP Tracing and IP Tracking
With our IP address tracer you can track and trace any IP addresses and website. We use probably the most accurate IP address to location database to determine the IP location.
SQL Replication
Scaling with MySQL replication | Dries Buytaert
To deal with Drupal’s growth, we’re adding a second database server to drupal.org
which is useful for at least two reasons. First, we’ll be able to
handle more SQL queries as we can distribute them between multiple
database servers (load balancing). Secondly, this new server can act as a “hot spare” that can immediately take over if the other database server fails (high availability / fail-over).
The current plan is to configure both database servers in master-slave configuration,
which is the most common replication model for websites. This model
provides scalability, but not necessarily fail-over. With a
master-slave configuration, all data modification queries (like INSERT, UPDATE and DELETE
queries) are sent to the master. The master writes updates to a binary
log file, and serves this log file to the slaves. The slaves read the
queries from the binary log, and execute them against their local copy
of the data. While all data modification queries go to the master, all
the read-only queries (most notably the SELECT queries)
can be distributed among the slaves. By following this model, we can
spread the workload amongst multiple database servers. And as
Drupal.org’s traffic continues to grow, we can scale horizontally by
adding more slaves.
While MySQL does the database replication work, it doesn’t do the
actual load balancing work. That is up to the application or the
database abstraction layer to implement. To be able to distribute
queries among multiple database servers, the application needs to
distinguish between data modification queries and read-only queries.
Care needs to be taken, as the data on the slaves might be slightly
out of sync. It may or may not be practical to guarantee a low-latency
environment. In those cases, the application might want to require that
certain read-only queries go to the master.
There are different ways to accomplish this:
* Drupal executes all SQL queries through db_query(). Traditionally, big Drupal sites manually patched db_query() to use query parsing (regular expression foo) to separate read queries from write queries. This is not convenient and it doesn’t provide a good solution to deal with lag. Fortunately, work is being done to provide better support for database replication in Drupal 6. It’s our intend to backport this to Drupal 5 so we can use it on drupal.org until Drupal 6 has been released and drupal.org has been upgraded to use Drupal 6.
* MediaWiki, the software behind Wikipedia uses $db->select() and $db->insert(). They have some documented best practices to deal with lag.
* Neither the Pear DB database abstraction layer or its successor Pear MDB2 seem to support database replication.
* WordPress uses HyperDB, a drop-in replacement for WordPress’ default database abstraction layer that provides support for replication. It was developed for use on WordPress.com, a mass hosting provider for WordPress blogs. Because HyperDB is a drop-in replacement, they don’t have a clean API and just like Drupal 5, they have to use query parsing to separate read queries from write queries. It’s not clear how they deal with lag.
* Joomla! 1.0 does not separate read queries from write queries, but Joomla! 1.5 will use functions like $db->insertObject() and $db->updateObject(). Joomla! 1.5 won’t support replication out of the box, but their API allows a clean drop-in replacement to be developed. It’s not clear how they would deal with lag.
* PostNuke uses the ADOdb database abstraction library, which at first glance does not support database replication either.
* Java applications use the statement.executeQuery() and statement.executeUpdate() that are part of the standard class libraries. It’s not clear how they deal with lag.
What Is GEO I/O?
Real-time Geographic IP Service – Free Geolocation Database
Developers use GEO I/O to resolve IP addresses to geographic locations for powering forms, maps and many other applications. Some of the information available includes latitude and longitude, zip and postal codes, telephone area codes and more. [Get further details]
www.ipmango.com
MySQL Change root Password + Linux
mysqladmin command to change root password
If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD
However, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p oldpassword newpass
Enter password:
Change MySQL password for other userTo change a normal user password you need to type (let us assume you would like to change password for vivek):
$ mysqladmin -u vivek -p oldpassword newpass
Changing MySQL root user password using mysql sql command
This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:
1) Login to mysql server, type following command at shell prompt:
$ mysql -u root -p
2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;
3) Change password for user vivek:
mysql> update user set password=PASSWORD(“NEWPASSWORD”) where User=’vivek’;
4) Reload privileges:
mysql> flush privileges;
mysql> quitThis method you need to use while using PHP or Perl scripting.
Leave a Comment
Comments (1)
Leave a Comment