Showing posts with label Unix/Linux Administration. Show all posts
Showing posts with label Unix/Linux Administration. Show all posts

Monday, May 16, 2011

A Bash Script Template

#!/bin/sh

#---------------------------------------
# Script Description/Usage:
# To perform start/stop/restart of ......
#---------------------------------------
# Modification History:
# Jan 01, 2011 : A.Nie : initial creation
#---------------------------------------
#

RETVAL=0

# Check input arguments
if [ $# -ne 1 ] ; then
  echo "Usage: `basename $0` {start|stop|restart}"
  RETVAL=1
  exit $RETVAL
fi

# Check running user
if [ `id -un` != "root" ] ; then
  echo "Must run the script as root, exiting..."
  RETVAL=2
  exit $RETVAL
fi

# Define variables
VAR1=VARVALUE1
......

# Start function
start() {
          ......
}

# Stop function
stop() {
          ......
}

# Restart function
restart() {
             stop
             start
}

# Main
# While LOOP
while [ condition ] ; do
  ......
done

# For LOOP
for VAR in ...... ; do
  ......
done

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        restart
        ;;
*)
        echo "Usage: $0 {start|stop|restart}"
        RETVAL=3
        ;;
esac

exit $RETVAL

Monday, March 14, 2011

Daylight time saving - issue with cron jobs

I had two Unix cron jobs to stop then start Oracle instances and listeners on Sundays weekly. It had run fine until this Monday morning my developers reported that they couldn't connect to Oracle.

After investigation I found the culprit being the daylight time saving. The stop job was scheduled @2:15am and the start job @3:00am. From the logs I found the stop jobs was actually kicked off @3:00am due to the daylight time saving, as well as the start job, so both jobs were run at the same time, which caused the listeners were not started.

So suggestion is not to schedule jobs between 2~3am on Sundays.

Thursday, October 14, 2010

Linux memory usage

  • Do a free command, see the used, free memory, as well buffers and cached memory
        

  • Do a total of all running procecss memory usage, including init, the kernel is not reported in "ps"
$ ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid|grep -v RSS|awk '{total=total+$3}END{print total}'

2194756
  • How much used for kernel
Total physical RAM - buffers - cached - total running process RAM usage - free:
8175520 - 535184 - 3158588 - 2194756 - 2105836 = 92236KB

Notes:
  • Reference: http://mail.nl.linux.org/linux-mm/2003-03/msg00077.html
  •  Memory Buffers - A page cache for the virtual memory system. The kernel keeps track of frequently accessed memory and stores the pages here.
  • Memory Cached - Any modern operating system will cache files frequently accessed.
  • VSIZE (Virtual memory SIZE) - The amount of memory the process is currently using. This includes the amount in RAM (including buffers/cached) and the amount in swap.
  • RSS (Resident Set Size) - The portion of a process that exists in physical memory (RAM).
  • The kernel - The kernel will consume a couple of MB of memory. The memory that the kernel consumes can not be swapped out to disk. This memory is not reported by commands such as "free" or "ps".