----------------------------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"`
Showing posts with label Solaris. Show all posts
Showing posts with label Solaris. Show all posts
Thursday, January 20, 2011
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"
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"
Useful monitoring command of Unix/Linux Vol.2
Change ownership of a directory: chown -Rv username somedir
Change usergroup or a directory: chgrp -Rv usergroup somedir
To set environment variable: setenv
To load the control file: source <filename> (Shell csh only)
To enable sqlplus/Oracle at the first run:
setenv ORACLE_HOME /opt/app/oracle/product/10.2.0/Db_1
setenv ORACLE_SID ASMDB003
setenv ORACLE_TRACE T
setenv ORAENV_ASK NO
setenv NLS_LANG American_America.we8iso8859p1
setenv LD_LIBRARY_PATH /usr/lib:/usr/ucblib:/usr/local/lib:/opt/SUNWspro/lib:$OR
ACLE_HOME/lib:$ORACLE_HOME/precomp/lib:$ORACLE_HOME/rdbms/lib:$ORACLE_HOME/jdbc/
lib:$ORACLE_HOME/dbjava/lib:/user/sfw/lib
setenv PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/cc
s/bin:/opt/SUNWspro/bin:${ORACLE_HOME}/bin
setenv PATH ${PATH}:${HOME}/bin
Change usergroup or a directory: chgrp -Rv usergroup somedir
To set environment variable: setenv
To load the control file: source <filename> (Shell csh only)
To enable sqlplus/Oracle at the first run:
setenv ORACLE_HOME /opt/app/oracle/product/10.2.0/Db_1
setenv ORACLE_SID ASMDB003
setenv ORACLE_TRACE T
setenv ORAENV_ASK NO
setenv NLS_LANG American_America.we8iso8859p1
setenv LD_LIBRARY_PATH /usr/lib:/usr/ucblib:/usr/local/lib:/opt/SUNWspro/lib:$OR
ACLE_HOME/lib:$ORACLE_HOME/precomp/lib:$ORACLE_HOME/rdbms/lib:$ORACLE_HOME/jdbc/
lib:$ORACLE_HOME/dbjava/lib:/user/sfw/lib
setenv PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/cc
s/bin:/opt/SUNWspro/bin:${ORACLE_HOME}/bin
setenv PATH ${PATH}:${HOME}/bin
Useful monitoring command of Unix/Linux Vol.1
For Solaris Only:
check number of core: prtdiag -v
create new user: useradd jsmith
get user information: finger jsmith
set password: passwd jsmith
set default home directory: usermod -d /path/to/new/homedir/ username
set default Shell: change permenently the SHELL at etc/passwd
check Solaris release: cat /etc/release
Check current shell: echo $SHELL
Check shell version: /bin/bash --version
check number of core: prtdiag -v
create new user: useradd jsmith
get user information: finger jsmith
set password: passwd jsmith
set default home directory: usermod -d /path/to/new/homedir/ username
set default Shell: change permenently the SHELL at etc/passwd
check Solaris release: cat /etc/release
Check current shell: echo $SHELL
Check shell version: /bin/bash --version
Subscribe to:
Posts (Atom)