Pages

Friday, January 14, 2011

Grant & Revoke access on PostgreSQL

Grant manual:
http://www.postgresql.org/docs/8.3/static/sql-grant.html

Revoke manual:
http://www.postgresql.org/docs/8.2/static/sql-revoke.html

By default, postgresql doesn't provide syntax for grant/revoking privileges from all tables, to do it just follow simple tricks:

=== quoted from http://postgresql.1045698.n5.nabble.com/REVOKE-from-all-tables-td2077327.html ===
I like doing things like with just psql as shown below. And, I get to
look at the commands before running them.  For example: something
like this to revoke all for all tables in the public schema:

  -- Turn off headers:
  \t
  -- Use SQL to build SQL:
  SELECT 'REVOKE ALL ON public.' || table_name || ' FROM PUBLIC;'
  FROM information_schema.tables
    WHERE table_type = 'BASE TABLE' AND table_schema='public';
  -- If the output looks good, write it to a file and run it:
  \g out.tmp
  \i out.tmp

It works pretty well on similar tasks, at least until you run into string
quote/escape problems.

=== end quote ===

Some Code Igniter Tricks

Enable remote access to PostgreSQL

There are few steps:

  • Alow firewall for pgsql port and target IP 
  • Enable client authentication (pg_hba.conf)
    • host all all 10.10.29.0/24 trust
  • Allow TCP/IP socket (postgresql.conf)
    • listen_addresses='*'
    • for version upto 7.x use tcpip_socket = true
refs:

Tuesday, January 11, 2011

Using Apache's htaccess Authentication

At least there are 3 things you should do:
- set the .htaccess and .htpasswd files on target folder. This will protect access to the folder contents, including subfolders.
- configure httpd.conf [make sure AllowOverride All on <Directory "/document/root">]

this link is nice reference:
http://www.sitedeveloper.ws/tutorials/htaccess.htm

Monday, January 10, 2011

Print formatted date in shell script

#!/bin/bash
date=`date +%Y/%m/%d_%H:%M`
if tail -1 /home/asd/testlog|grep Error
then
        echo "$date | ups there's an error! restarting smsd ...">>/home/asd/cron.log;
fi

refs:

Scheduling jobs with Crontab

Crontab Commands
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 File Configuration
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)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
Notes
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
note: in Ubuntu 10.10, cron activity can be found in /var/log/syslog
reference/further read:
http://adminschoice.com/crontab-quick-reference
http://team.macnn.com/drafts/crontab_defs.html
http://perl.ericdlarson.com/crontab.html
http://www.tutorial5.com/content/view/95/51/
http://www.crontabrocks.org/
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
http://ubuntuforums.org/showthread.php?t=586478
http://www.unixgeeks.org/security/newbie/unix/cron-1.html