Hi all


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hi all
# 1  
Old 12-18-2008
Hi all

I have run the following program but i am getting the error: The programs is below

Code:
#!/usr/bin/ksh

# This script injects tapes from the inport 
# If the argument -c is passed it runs until CRTL-C is pressed.
# It logs in a logfile of the type /tmp/tldtest.<YYYYMMDD>

DATE=`date +'%D %X'`
logdate=`date +'%Y%m%d'`
echo "" >> /tmp/tldtest.$logdate
echo "$DATE TAPE INJECT STARTED" >> /tmp/tldtest.$logdate
count=0
while [ "$1" = "-c" -o $count -lt 1 ]
do
TRY=1
ERRORCODE=1
while [ $ERRORCODE -gt 0 -a $TRY -lt 4 ]
do
# check if there are any empty slots in the robot according to netbackup
/usr/openv/volmgr/bin/vmcheckxxx -rt tld -r 0 -rh sapbck1 | grep empty | cut -c 14- > /tmp/emptyslots 2>&1
ERRORCODE=$?
if [ $ERRORCODE -ne 0 ]; then
sleep 10
let TRY=${TRY}+1
fi
done

if [ ! -s /tmp/emptyslots ]; then
echo "NO EMPTY SLOTS"
exit 0
fi
EMPTY="yes"
while [ "$EMPTY" != "no" ]
do
# examine the inport
echo "s i" | /usr/openv/volmgr/bin/tldtest -r /dev/sg/c2t0l0 | tail +3 > /tmp/inport 2>&1
SOURCE=`grep Source /tmp/inport`
if [ -n "$SOURCE" ];then
  echo "Ejected tapes in inport" >> /tmp/tldtest.$logdate
  echo "TAPE INJECT COMPLETED" >> /tmp/tldtest.$logdate
  exit 0
fi

# check if the inport slots are full and find the connection between inport slot and mediaid
/bin/rm -f /tmp/mediainport
nr=1
cat /tmp/inport |
while read line
do
read line2 line3
fullyes=`/bin/echo "$line $line2 $line3" | grep full | sed 's/^.*full...//'`
if [ "$fullyes" = "1" ]; then
  read var1 var2 mediaid
  echo "port$nr $mediaid" >> /tmp/mediainport
  EMPTY="no"
fi
let nr=${nr}+1
done

# clean up and exit if the inport is empty 
if [ ! -e /tmp/mediainport ]; then
if [ "$1" = "-c" ]; then
sleep 120
else
/bin/rm -f /tmp/emptyslots /tmp/inport /tmp/mediainport
exit 0
fi
fi
done
# move media in inport to the empty slots
nr=1
tail -4 /tmp/emptyslots |
while read var slot line
do
cat /tmp/mediainport | grep "port$nr" | read port mediaid

# if inport slot nr contains media move it and update netbackup volume database
if [ -n "$mediaid" ]; then
echo "TAPE: $mediaid" >> /tmp/tldtest.$logdate
echo "m i$nr s$slot" | /usr/openv/volmgr/bin/tldtest -r /dev/sg/c2t0l0 >> /tmp/tldtest.$logdate 2>&1
/usr/openv/volmgr/bin/vmquery -m $mediaid 1> /dev/null 2>&1
 if [ $? -eq 35 ] ; then 
   /usr/openv/volmgr/bin/vmadd -m $mediaid -mt dlt 
   /usr/openv/volmgr/bin/vmchange -res -m $mediaid -b $mediaid -mt dlt -rt tld -rn 0 -rc1 $slot -rh sapbck1
   /usr/openv/volmgr/bin/vmchange -m $mediaid -p 5
 else
   /usr/openv/volmgr/bin/vmchange -res -m $mediaid -b $mediaid -mt dlt -rt tld -rn 0 -rc1 $slot -rh sapbck1 
   /usr/openv/volmgr/bin/vmchange -m $mediaid -p 5 >> /tmp/tldtest.$logdate 2>&1
 fi
fi
let nr=${nr}+1
done
let count=${count}+1
done
# general clean up
/bin/rm -f /tmp/emptyslots /tmp/inport /tmp/mediainport /tmp/tapesinrobot
echo "TAPE INJECT COMPLETED" >> /tmp/tldtest.$logdate
echo "" >> /tmp/tldtest.$logdate
# ./robot.ksh

./robot.ksh: line 16: [: TRY: integer expression expected
tail: cannot open input
#


Last edited by zaxxon; 12-18-2008 at 11:02 AM.. Reason: Added code tags
# 2  
Old 12-18-2008
1. Such nonthing saying subjects normally get you an infraction. Rules are to use senseful subjects.
2. Please use code tags. It's no fun reading such scripts with no formatting. I edited your post - it now has code tags.
3. Please try it again with doube square brackets like:
Code:
while [[ $ERRORCODE -gt 0 -a $TRY -lt 4 ]]

4. Also to be sure maybe start using variables in this form:
Code:
${VAR}

5. Use set -x to debug your script
6. Use echo on your variables to debug your script
# 3  
Old 12-18-2008
This is the line 16


16 while [ TRY -lt 4 -a "$word1" != "slot" ]
# 4  
Old 12-18-2008
I am sorry for my mistake.
# 5  
Old 12-18-2008
Np. My suggestions also apply to this line. It applies to all lines using those square brackets. Change them to [[ ]] and try again.
# 6  
Old 12-18-2008
I try the way you told me but getting the following error

# ./robot.ksh
++ TRY=1
++ word1=
./robot.ksh: line 16: syntax error in conditional expression
./robot.ksh: line 16: syntax error near `-a'
./robot.ksh: line 16: `while [[ TRY -lt 4 -a "$word1" != "slot" ]]'
#




Quote:
Originally Posted by zaxxon
1. Such nonthing saying subjects normally get you an infraction. Rules are to use senseful subjects.
2. Please use code tags. It's no fun reading such scripts with no formatting. I edited your post - it now has code tags.
3. Please try it again with doube square brackets like:
Code:
while [[ $ERRORCODE -gt 0 -a $TRY -lt 4 ]]

4. Also to be sure maybe start using variables in this form:
Code:
${VAR}

5. Use set -x to debug your script
6. Use echo on your variables to debug your script
# 7  
Old 12-18-2008
You try to compare a string/text with a number:
Problem is here:
Code:
while [[ TRY -lt 4

Your variable $ERRORCODE has no number to be compared if it is less than 4, but it contains the string "TRY".
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question