Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Sunday, August 14, 2011

How to move 2Gb or bigger file in a script

#!/bin/sh

find /backup/include -printf '%s %p\n' | while read size name; do
    if [ "$size" -gt 2000000000 ]; then
        mv -i "$name" /backup/exclude
    fi
done
  

Thursday, January 20, 2011

Script that Generates Report from Oracle DB

------------------------------Script---------------------------------

#!/bin/sh

ORACLE_HOME=/opt/oracle
export ORACLE_HOME
ORACLE_BASE=/opt/oracle
export ORACLE_BASE
ORACLE_OWNER=oracle
export ORACLE_OWNER
ORACLE_SID=DB_NAME
export ORACLE_SID
NLS_LANG="american_america.we8iso8859p1"
export NLS_LANG

PATH=/usr/bin:/bin:/usr/local/bin:$ORACLE_HOME/bin
export PATH

outfile="/export/home/`date +"%Y%m%d"`.txt"

sqlplus -s username/password@DB_Name @$HOME/gen_report.sql > $outfile

----------------------------SQL File--------------------------------

select USER_ID as A, B, to_char(TIMESTAMP,'hh:mi:ssam') as Time From Table WHERE to_char(TIMESTAMP,'DD-Mon-YY') = (select to_char(sysdate, 'DD-Mon-YY') from dual) AND CONDITION_A = 'true' order by timestamp;

whenever sqlerror exit 99
whenever oserror exit 88
set pages 1000 echo off verify off feedback off

alter session set nls_date_format='YYMMDD HH24:MI:SS';
set line 200
col user_id format a15
col remarks format a50

select USER_ID as A, B, to_char(TIMESTAMP,'DD-Mon-YY hh:mi:ssam') as Time From username.table_name WHERE to_char(TIMESTAMP,'DD-Mon-YY') = (select to_char(sysdate-1, 'DD-Mon-YY') from dual) AND Condition_A = 'true' order by timestamp;

exit


Get Date of Yesterday

----------------------------Ksh Shell Script--------------------------------

#! /usr/bin/ksh
# Get yesterday's date in YYYY-MM-DD format.
# With argument N in range 1..28 gets date N days before.
# Tapani Tarvainen January 2002
# This code is in the public domain.

OFFSET=${1:-1}

case $OFFSET in
  *[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac

eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year

# Subtract offset from day, if it goes below one use 'cal'
# to determine the number of days in the previous month.
day=$((day - OFFSET))
if (( day <= 0 )) ;then
  month=$((month - 1))
  if (( month == 0 )) ;then
    year=$((year - 1))
    month=12
  fi
  set -A days `cal $month $year`
  xday=${days[$(( ${#days[*]}-1 ))]}
  day=$((xday + day))
fi

print $year-$month-$day
print $month/$day/${year#??}


------------------------Bash Shell Script------------------------------

#!/bin/bash

OFFSET=1;

eval `date "+day=%d; month=%m; year=%Y"`

# Subtract offset from day, if it goes below one use 'cal'

# to determine the number of days in the previous month.

day=`expr $day - $OFFSET`

if [ $day -le 0 ] ;then

month=`expr $month - 1`

if [ $month -eq 0 ] ;then

year=`expr $year - 1`

month=12

fi

set `cal $month $year`

xday=${$#}

day=`expr $xday + $day`

fi

echo $year-$month-$day


------------------------- Linux--------------------------

curdate=`date +%y%m%d -d "yesterday"`

Write Script with arithmetic Operations

#!/bin/sh
echo "enter two numbers"
read a b
c=$(($a+$b))
echo "$a + $b = $c"
# or
let c="$a+$b"
# or
c=`expr $a + 1`

echo "$a + $b is $c"