Monday, October 5, 2009

Atom 1.0

http://dev.fyicenter.com/faq/rss/rss_atom_feed_file_structure_and_elements.php

Tuesday, May 26, 2009

HTACCESS

RewriteEngine on

#Send output from web server in GZip format to fast transfer over the internet


SetOutputFilter DEFLATE



RewriteRule ^index.html$ /csn/index.php [L]
RewriteRule ^home.html$ /csn/index.php?file=home [L]
RewriteRule ^change-password.html$ /csn/index.php?file=change_password [L]
RewriteRule ^products.html$ /csn/index.php?file=products [L]
RewriteRule ^forgot-password.html$ /csn/index.php?file=forgot_password [L]
RewriteRule ^login.html$ /csn/index.php?file=login [L]
RewriteRule ^logout.html$ /csn/index.php?file=logout [L]
RewriteRule ^signup.html$ /csn/index.php?file=signup [L]
RewriteRule ^pdetail-([0-9]+).html$ /csn/index.php?file=product_detail&pid=$1 [L]
RewriteRule ^products/p([0-9]+).html$ /csn/index.php?file=products&SPTPage=$1 [L]
RewriteRule ^confirm-request.html$ /csn/index.php?file=confirm_request [L]
RewriteRule ^contact-confirm.html$ /csn/index.php?file=sent_confirm_request [L]


#---------------------------CONTENT PAGE RULE--------------------------------#
RewriteRule ^terms__conditions.html$ /csn/index.php?file=content&page=terms__conditions [L]
#---------------------------CONTENT PAGE RULE--------------------------------#

#---------------------------CONTENT PAGE RULE--------------------------------#
RewriteRule ^privacy_policy.html$ /csn/index.php?file=content&page=privacy_policy [L]
#---------------------------CONTENT PAGE RULE--------------------------------#

#---------------------------CONTENT PAGE RULE--------------------------------#
RewriteRule ^faq.html$ /csn/index.php?file=content&page=faq [L]
#---------------------------CONTENT PAGE RULE--------------------------------#

#---------------------------CONTENT PAGE RULE--------------------------------#
RewriteRule ^contact_us.html$ /csn/index.php?file=content&page=contact_us [L]
#---------------------------CONTENT PAGE RULE--------------------------------#

#---------------------------CONTENT PAGE RULE--------------------------------#
RewriteRule ^testing_page.html$ /csn/index.php?file=content&page=testing_page [L]
#---------------------------CONTENT PAGE RULE--------------------------------#

Monday, April 13, 2009

Cron Job script

Use the command 'man man' to see why the '-s 5' needed to be used to view the second crontab man page.
Using Cron
To use cron, it is easiest to start with a blank slate. The crontab command will do that for me, but by default I will need to know how to edit and save files with vi. If I am not comfortable with vi, and do not want to learn to use it, I can use another editor. To use nano (after making sure it is installed with 'which nano'), I could execute this command:
  $ export EDITOR=nano
before using the crontab command:
  $ crontab -e
which will start the editor (or vi) and load the current cron table file for this user, or a blank file if none exists.
If I don't want to set a MAILTO email address (after reading about it in the documentation above), the first line I want in my crontab is a comment. More specifically, this comment:
  #mh hd dm my dw command
(every line starting with a pound symbol (#) is a comment) because it reminds me that the space separated fields are:
  • minute of the hour
  • hour of the day
  • day of the month
  • month of the year
  • day of the week
  • command line
The command can contain spaces (and need not be quoted), but the other fields must not contain spaces.
Since I like the output and format of the top command, I'll research it a bit (using the 'man top' and 'top --help' commands) and put together a command line I can use in a cron job:
  /usr/bin/top -n 1 -b -S
Notice that I used the whole path to the top executable. Since cron jobs may not provide the same working environment (path, aliases, ...) I get at the command prompt, it is wise to use full paths to all commands and scripts I use. I test the command a couple times to make sure I get the output I thought I was going to get. The output of this command (by default) will be sent to my user via email whenever this cron job executes.
Crontab Examples
To use this command on cron job line using 'crontab -e', I need to fill in all of the fields:
  0 12 * * * /usr/bin/top -n 1 -b -S
This command will execute every day at noon. The first five fields can be values, lists, ranges, or ranges with step values.
The first and second fields in the example are values. They are just simple integers that exist in the range of the field. The '0' in the first field could be any integer between '0' and '59' (minutes of the hour). The '12' in the second field could be any integer between '0' and '23' (hours of the day).
A list is more than one value separated by commas (with no spaces). An example using lists would be:
  0 0,6,12,18 * * * /usr/bin/top -n 1 -b -S
which adds midnight (0), 6 am (6), and 6 pm (18) to the times this job will execute, in addition to the original time of noon (12).
A range is just a lower number (in the range of possible values) and a higher number (also in the range of possible values) separated by a dash ('-'). A cron job using a range might be:
  0 0,6,12,18 * * 1-5 /usr/bin/top -n 1 -b -S
making the 'top' cron job execute four times a day, but only on weekdays (Monday through Friday). A list may also include a range in place of one (or more) of its values, like this:
  0 0,6,9-15,18 * * 1-5 /usr/bin/top -n 1 -b -S
which would allow this cron job to execute every hour from 9 am (9) until 3 pm (15), instead of just at noon (12).
The asterisk (*) fields in the example above are ranges, consisting of every value in the range from the first possible value through the last possible value, which are different for each field. In the original example, the third fields asterisk means '1-31' (days of the month), the fourth fields asterisk means '1-12' (months of the year), and the fifth fields asterisk means '0-7' (days of the week, Sunday being both values zero (0) and seven(7)).
Ranges with step values express lists like this:
  0 0,6,12,18 * * * /usr/bin/top -n 1 -b -S
in this abbreiviated way:
  0 */6 * * * /usr/bin/top -n 1 -b -S
meaning all possible values ('*' or '0-23') that are evenly divisible by 6 (0, 6, 12, and 18). This way of expressing lists makes it much easier to run a cron job every 5 minutes:
  */5 * * * * /usr/bin/top -n 1 -b -S
or every other day:
  0 12 */2 * * /usr/bin/top -n 1 -b -S
in a way that is short, easy to read, and interpret.
Cron Job Output
Sometimes I never want to receive the output of a command I put in my crontab. There are a couple of way to do this. The "all or nothing" way is to set MAILTO="" on the first line of my crontab, but then I will get no output (that I don't arrange to get somehow via the command) for any of my cron jobs. I typically do not do this.
I regularly use output redirection to funnel my command output to a file (if I want a more permanent record of the cron job than an email), or to the 'electronic wastebin' (or 'bitbucket') which is /dev/null (if I want no record of the cron job). If I want to ping a list of hosts every 10 minutes, I can write a script called 'pinghosts.sh' that provides nicely formatted output from the 'ping' command. The script could automatically put it's output to a file, but if I want to use 'pinghosts.sh' from the command line too, that might be a problem. Instead, I could do this:
  */10 * * * * /home/myuser/bin/pinghosts.sh > /home/myuser/pinghosts.log
and every ten minutes the output of 'pinghosts.sh' will replace the contents of the file 'pinghosts.log' ('>' causes the output of the 'pinghosts.sh' command to overwrite the contents of the 'pinghosts.log' file) in my home directory (if 'myuser' is my username). If I want 'pinghosts.log' to be more like a regular log file, tracking output over time, I need to use a different redirection symbol:
  */10 * * * * /home/myuser/bin/pinghosts.sh >> /home/myuser/pinghosts.log
('>>' cause the output of the 'pinghosts.sh' command to be appended to the 'pinghosts.log' file). If I plan to keep 'pinghosts.sh' output over time, I should make sure it doesn't produce more output that I have disk (or quota) space. I could just throw away the file when it gets to large, or maybe just every month or so (hmm...sounds like a job for cron).
If 'pinghosts.sh' produces any error messages, 'pinghosts.log' will not contain them. Instead, an email message containing the error messages will be sent to my user. If that is what I want, I am set, but many times I want error messages to be recorded in my logs of output, so the above examples will not do. To put all output into the file I need to do this [1]:
  */10 * * * * /home/myuser/bin/pinghosts.sh >> /home/myuser/pinghosts.log 2>&1
This works for shells like 'bash' (sh, ksh, zsh) and redirects STDERR (error output) to STDOUT (normal output), just after STDOUT has been redirected to the file 'pinghosts.log'.
Sometimes I just want a cron job script to do what I want and never tell me about it. If I have a script that notifies me by email of "garbage day" every week, I don't want another email telling me it sent the first email successfully. To make this happen, instead of a log file I use /dev/null as the target of my output:
  0 19 * * 2 /home/myuser/bin/garbage-day-email.sh > /dev/null 2>&1
but this will never alert me if the email is unsuccessful, so I may opt for this version:
  0 19 * * 2 /home/myuser/bin/garbage-day-email.sh > /dev/null
instead. This way, at 7 pm on Tuesday evenings I will get an email cheerfully reminding me of "garbage day", or an uglier error message that does the same (if email is working).