Friday, December 31, 2004

Shell Script - determine the directory where script is run from

>On 2004-11-08, Petterson Mikael wrote:
>
>>>> How can I determine the directory where my script is run from.
>>>> I need to use that to assign a variable $MY_HOME. It will be used when
>>>> I call files that are in the same directory or subdirectory to my
>>>> executing script.
>
>>
>> Maybe this one?
>> #v
>> MY_HOME=`which $0`
>> #v-


which is a command to be avoided. It's not builtin the shell
(except in tcsh and zsh).
Depending on the implementation, it may have nasty side effects
such as sourcing a ~/.cshrc in your home directory...

The POSIX command to find a command in $PATH is "command -v --"
But note that the command above would only be valid in bogus
versions of ksh (not pdksh nor recent versions of ksh93). The
shell is not supposed to look for the command in $PATH (if it
contains no slash and there's no such file in the current
directory, the shell may look it up in $PATH as do bash and the
fixed versions of ksh93, but that means it doesn't apply to
scripts run with the she-bang mechanism).

Note that $0 may be like ../foo.sh. So you'd need to do a get
the full directory (using cd -P ... && pwd -P)

For POSIX shells (bash/pdksh/zsh/BSDs sh...)

PROG_DIR=$(
prog=$0
[ -e "$prog" ] || prog=$(command -v -- "$0") # for "sh foo"
# where there's
# no foo in cwd
cd -P -- "$(dirname -- "$prog")" && pwd -P
)

For /broken/ versions of ksh (most):

PROG_DIR=$(
prog=$(command -v -- "$0")
cd -P -- "$(dirname -- "$prog")" && pwd -P
)

Note that both are generally equivalent. They may be different
in cases that seldom occur in real life.


____________________________________________

If you mean the current working directory, then it's $(pwd -P),
if you mean the path to the script when it was run, then it's
(assuming a POSIX shell):

$(cd -P -- "$(dirname -- "$0")" && pwd -P)

with ksh up to recent versions of ksh93:

$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)

(but be sure you use that before any command that would modify
PATH or the current working directory in your script).

Tuesday, December 28, 2004

SQL Server Hardware Performance Checklist

SQL Server Hardware Performance Checklist: "SQL Server Hardware Performance Checklist

Brad M. McGehee | Contributing Writer | 2004-12-10


Auditing SQL Server Hardware Is An Important Early Step

From this previous article, on using Performance Monitor, you may have identified some potential hardware bottlenecks that are negatively affecting your SQL Server's performance. In this section, we will take a look at each of the major components of a SQL Server's hardware, and examine what can be done to help maximize the performance of your hardware.

This portion of the audit will be divided into these major sections:

# CPU

# Memory

# Disk Storage

# Network Connectivity

# Misc.


As part of this audit, you will want to complete the above checklist. As you do, you may find out things about server you were not aware of.

CPU

Number of CPUs

This first point is obvious, the more CPUs your SQL Server has, the faster it can perform. The standard edition of SQL Server 2000 can support up to 4 CPUs. The Enterprise version can support up to 32 CPUs, depending on the OS used. Multiple CPUs can be effectively used by SQL Server to boost overall performance.

It is very difficult to estimate the number of CPUs any specific SQL Server-based application will need. This is because each application works differently and is used differently. Experienced DBAs often have a feel for what kind of CPU power an application might need, although until you really test your server's configuration under realistic conditions, it is hard to really know what is needed.

Because of the difficulty of selecting the appropriate numbers of CPUs to purchase of a SQL Server, you might want to consider the following rules of thumb:

# Purchase a server with as many CPUs as you can afford.


# If you can't do the above, then at least purchase a server that has room to expand its total number of CPUs. Almost all SQL Server"

Tuesday, August 24, 2004

xbindkeys

xbindkeys

A great meta-key for use with XBindkeys is the "Windows" key, which sits idly on so many keyboards. Chances are it's unused, so it won't conflict with anything. Say you have a script called "backup" that you like to run manually. This is how to bind it to the "Windows" and F5 keys with XBindkeys.

Run the command:

$ xbindkeys -mk

Then, press the "Windows" key; then, F5; then, q to quit. It will generate keycodes like this:

--- Press "q" to stop. ---
"NoCommand"
m:0x50 + c:115
Mod2+Mod4 + Super_L
"NoCommand"
m:0x10 + c:71
Mod2 + F5

Choose one line from each set of keycodes, and make this entry in $HOME/.xbindkeysrc:

"backup"
m:0x50 + c:115 + m:0x10 + c:71

Now, when you press the "Windows" and F5 keys, your backup script will run.

Sunday, August 01, 2004

Oracle - Turning archive logging on and off

Start.

1. add the following to init.ora file

log_archive_start = true
log_archive_dest = /path/to/archive/dir
log_archive_format = _%s.log

2. Starting archive logging

startup mount exclusive
alter database archivelog;
alter database open;

3. Check to make sure
SQL> archive log list
Database log mode ARCHIVELOG
Automatic archival ENABLED
Archive destination /path/to/archive/dir
Oldest online log sequence 2
Current log sequence 3

Stop.

1.
startup mount exclusive
alter database noarchivelog;
alter database open;
2.
SQL> archive log list
Database log mode NOARCHIVELOG
Automatic archival ENABLED
Archive destination /path/to/archive/dir
Oldest online log sequence 2
Current log sequence 3
SQL>

Monday, July 26, 2004

Oracle - Transportable Tablespaces

  • Make the tablespace Read-Only = alter tablespace xxxx read only;
  • Export it connecting as sys as sysdba = exp file=tt.dmp log=tt.log tablespaces=xxxx transportable_tablespaces=y
  • Copy the .dmp file and the data_files to the destination
  • Put the tablespace back in write mode = alter tablespace xxxx read write;
  • In the destination offline and drop the tablespace if exists
  • Import = imp file=tt.dmp log=tt.log tablespaces=test transportable_tablespace=y datafiles=(......., ........)

Sunday, July 25, 2004

Sqlserver database maintenance--Free disk space.

schedule a job which uses the undocumented call xp_fixeddrives Or you can try with master..xp_cmdsh

Oracle :: Disk I/O, Events, Waits

Datafile I/O

DATAFILE I/O NOTES:

  • File Name - Datafile name
  • Physical Reads - Number of physical reads
  • Reads % - Percentage of physical reads

  • Physical Writes - Number of physical writes
  • Writes % - Percentage of physical writes
  • Total Block I/O's - Number of I/O blocks


  • Use this report to identify any "hot spots" or I/O contention
  • select  NAME,
    PHYRDS "Physical Reads",
    round((PHYRDS / PD.PHYS_READS)*100,2) "Read %",
    PHYWRTS "Physical Writes",
    round(PHYWRTS * 100 / PD.PHYS_WRTS,2) "Write %",
    fs.PHYBLKRD+FS.PHYBLKWRT "Total Block I/O's"
    from (
    select sum(PHYRDS) PHYS_READS,
    sum(PHYWRTS) PHYS_WRTS
    from v$filestat
    ) pd,
    v$datafile df,
    v$filestat fs
    where df.FILE# = fs.FILE#
    order by fs.PHYBLKRD+fs.PHYBLKWRT desc