Sponsored Content
Full Discussion: Hi all
Top Forums Shell Programming and Scripting Hi all Post 302269696 by ma466 on Thursday 18th of December 2008 09:55:22 AM
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
 
SMRSH(8)						      System Manager's Manual							  SMRSH(8)

NAME
smrsh - restricted shell for sendmail SYNOPSIS
smrsh -c command DESCRIPTION
The smrsh program is intended as a replacement for sh for use in the ``prog'' mailer in sendmail(8) configuration files. It sharply limits the commands that can be run using the ``|program'' syntax of sendmail in order to improve the over all security of your system. Briefly, even if a ``bad guy'' can get sendmail to run a program without going through an alias or forward file, smrsh limits the set of programs that he or she can execute. Briefly, smrsh limits programs to be in a single directory, by default /usr/adm/sm.bin, allowing the system administrator to choose the set of acceptable commands, and to the shell builtin commands ``exec'', ``exit'', and ``echo''. It also rejects any commands with the charac- ters ``', `<', `>', `;', `$', `(', `)', ` ' (carriage return), or ` ' (newline) on the command line to prevent ``end run'' attacks. It allows ``||'' and ``&&'' to enable commands like: ``"|exec /usr/local/bin/filter || exit 75"'' Initial pathnames on programs are stripped, so forwarding to ``/usr/ucb/vacation'', ``/usr/bin/vacation'', ``/home/server/mydir/bin/vaca- tion'', and ``vacation'' all actually forward to ``/usr/adm/sm.bin/vacation''. System administrators should be conservative about populating the sm.bin directory. For example, a reasonable additions is vacation(1), and the like. No matter how brow-beaten you may be, never include any shell or shell-like program (such as perl(1)) in the sm.bin direc- tory. Note that this does not restrict the use of shell or perl scripts in the sm.bin directory (using the ``#!'' syntax); it simply dis- allows execution of arbitrary programs. Also, including mail filtering programs such as procmail(1) is a very bad idea. procmail(1) allows users to run arbitrary programs in their procmailrc(5). COMPILATION
Compilation should be trivial on most systems. You may need to use -DSMRSH_PATH="path" to adjust the default search path (defaults to ``/bin:/usr/bin:/usr/ucb'') and/or -DSMRSH_CMDDIR="dir" to change the default program directory (defaults to ``/usr/adm/sm.bin''). FILES
/usr/adm/sm.bin - default directory for restricted programs on most OSs /var/adm/sm.bin - directory for restricted programs on HP UX and Solaris /usr/libexec/sm.bin - directory for restricted programs on FreeBSD (>= 3.3) and DragonFly BSD SEE ALSO
sendmail(8) $Date: 2004/08/06 03:55:35 $ SMRSH(8)
All times are GMT -4. The time now is 02:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy