The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in shell script arnie_nits Shell Programming and Scripting 1 12-12-2007 10:13 AM
Shell script problem shashi_kiran_v UNIX for Dummies Questions & Answers 5 01-10-2007 11:49 AM
shell script problem djt0506 UNIX for Dummies Questions & Answers 2 12-07-2005 11:29 PM
Problem with shell script zylwyz Shell Programming and Scripting 2 06-29-2005 02:01 PM
Problem with shell script nattynatty Shell Programming and Scripting 4 04-09-2002 04:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-18-2008
babu.knb babu.knb is offline
Registered User
  
 

Join Date: Sep 2008
Location: India
Posts: 7
Problem in shell script


Code:
 
HOSTNAME=`uname -n`
/usr/sbin/clinfo
CLUSTERACTIVE=$?
# First check whether the Cluster itself is active
if [ $CLUSTERACTIVE != "0" ]
  then
        echo Cluster is NOT ACTIVE - EXITING
          exit 1
  fi
# Now check whether we are on the active Cluster Node for this Resource Group
CLUSTERSTATE=`/usr/cluster/bin/scha_resource_get -R ora-db03-lh-rs -O RESOURCE_STATE_NODE $HOSTNAME`
if [ $CLUSTERSTATE != "ONLINE" ]
  then
        echo "Cluster is NOT ON ACTIVE CLUSTERNODE for this resource group - EXITING"
          exit 1
  fi
echo "Cluster status check OK"
### Cluster check done
# check whether correct User executes this Script
USERNAME=$LOGNAME
if [ ! $USERNAME = "root" ]
  then
        echo "WRONG USERNAME, must be User ROOT"
        exit 1
  fi
echo "User check OK"
### User check done
# Get command Line Parameters
INSTANCE=$1
USR=$2
# Now check whether required Parameter has been given on command Line
if [ ! $# = "2" ]
  then
        echo
        echo "Wrong number of Parameters or no Parameter have been given. USAGE: arc_aging.sh FIN/DIS ocafin1/oracle"
        echo
        exit 1
  else
        echo "Parameter count check OK"
  fi
# Now check whether valid Parameters have been given
if [ "$INSTANCE" = "FIN" -o "$INSTANCE" = "DIS" ]
  then
        echo "Parameter validation check OK"
  else
        echo "Parameter must be FIN or DIS !!"
        exit 1
  fi
if [ "$USR" = "ocafin1" -o "$USR" = "oracle" ]
  then
        echo "Parameter validation check OK"
  else
        echo "Parameter must be oracle or ocafin1 !!"
        exit 1
  fi
### Parameter check done
# Build local Environment Variables
INSTANCE_REDO=$1_REDO2
## Set the archive Directory
ARCH1="/global/$INSTANCE_REDO/archlogs"
ARCH2="/global/ORA_BACKUP/archlogs/$INSTANCE"
ARCH3="/global/ORA_BACKUP/archlogs/$INSTANCE/compressed"
ARCH4="/global/LOG_REPLICATION/$INSTANCE"
# Delete Archive logs on /global/LOG_REPLICATION/$INSTANCE volume when not accessed since 10 days
# These are the archive logs which where replicated to Euromoda/TIU via SNDR
echo "SNDR: Deleting Archive Logs on /global/LOG_REPLICATION/$INSTANCE older than 10 days ...."
date '+Start: %H:%M:%S'
echo "The following files are going to be deleted:"
su $USR -c "find $ARCH4 -type f -atime +10 -exec ls {} \;"
su $USR -c "find $ARCH4 -type f -atime +10 -exec rm {} \;"
echo Return code: $?
date '+End: %H:%M:%S'
# Delete Archive logs on /global/ORA_BACKUP volume when not accessed since 15 days
echo "Cleaning up Archive Logs on /global/ORA_BACKUP/archlogs/$INSTANCE/compressed older than 15 days ...."
date '+Start: %H:%M:%S'
echo "The following files are going to be deleted:"
su $USR -c "find $ARCH3 -type f -atime +10 -exec ls {} \;"
su $USR -c "find $ARCH3 -type f -atime +10 -exec rm {} \;"
echo Return code: $?
date '+End: %H:%M:%S'
 
# Compress Archive logs on /global/ORA_BACKUP volume when not accessed since 2 days
echo "Compressing Archive Logs on /global/ORA_BACKUP/archlogs/$INSTANCE older than 2 days ...."
date '+Start: %H:%M:%S'
su $USR -c "find $ARCH2 -name compressed -prune -o -type f -atime +2 -exec ls {} \;"
su $USR -c "find $ARCH2 -name compressed -prune -o -type f -atime +2 -exec compress {} \;"
echo Return code: $?
date '+End: %H:%M:%S'
# Move compressed files to subfolder
echo "Moving compressed files to subfolder ...."
date '+Start: %H:%M:%S'
su $USR -c "mv /global/ORA_BACKUP/archlogs/$INSTANCE/*.Z /global/ORA_BACKUP/archlogs/$INSTANCE/compressed"
su $USR -c "mv /global/ORA_BACKUP/archlogs/$INSTANCE/*.gz /global/ORA_BACKUP/archlogs/$INSTANCE/compressed"
echo Return code: $?
date '+End: %H:%M:%S'
# Move Archive logs from /global/(FIN/DIS)_REDO2/archlogs to the /global/ORA_BACKUP volume when not accessed since 1 day
echo "Moving Archive Logs to /global/ORA_BACKUP/archlogs/$INSTANCE older than 1 day ...."
date '+Start: %H:%M:%S'
su $USR -c "find $ARCH1 -name compressed -prune -o -type f -atime 1 -exec ls {} \;"
su $USR -c "find $ARCH1 -name compressed -prune -o -type f -atime 1 -exec mv {} /global/ORA_BACKUP/archlogs/$INSTANCE/ \;"
echo Return code: $?
date '+End: %H:%M:%S'
echo "Current Disc usage ...."
df -k|grep ORA
df -k|grep $INSTANCE_REDO


Code:
 
/root/scripts>./ARC-PURGE.sh ESPOS espos 2>&1 mailx -s "ESPOS Archivelog Purge" babu.knb@gmail.com
User check OK
Wrong number of Parameters or no Parameter have been given. USAGE: arc_purge.sh ESPOS/FPRINT espos/fprint

I got below error message. Please advice me what was the problem?
  #2 (permalink)  
Old 11-22-2008
moshe fried moshe fried is offline
Registered User
  
 

Join Date: Feb 2007
Location: Israel
Posts: 24
try if [ $# != 2 ] instead of if [ ! $# = 2 ]
  #3 (permalink)  
Old 11-22-2008
rc7 rc7 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Bash has a built-in operator -ne for integer comparison. I would re-write the code for checking number of argument as:
if [ $# -ne 2 ]; then
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0