Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help newbie to scripting

Status
Not open for further replies.

Sambo8

Programmer
May 10, 2005
78
0
0
NZ
Hi there,

The following is my script:

Code:
#/usr/bin/ksh
# this gets yesterdays day
SAM=$(TZ=CST+24 date '+%a')
echo $SAM
ERROR1=$(echo "Email backup not run PLEASE CHECK")
ERROR2=$(echo "Error in backup see backuperrordetails.log for details")
find /u01/app/oracle/work/sam/backup/backup.$SAM -mtime -1 -print > output
#
if [[ $(cksum /u01/app/oracle/work/sam/backup/output | nawk '{print $2}') -gt 0 ]]
then  echo "the file exist" > blah.txt
else echo "file doesn't exist send mail to say no backup" $ERROR1
fi
if [[ $(cksum /u01/app/oracle/work/sam/backup/blah.txt | nawk '{print $2}') -gt 0 ]]
then echo "gotta tail that file and send error" > problems.txt
else > problems.txt
fi
#
echo $SAM
if [[ $(cksum /u01/app/oracle/work/sam/backup/problems.txt | nawk '{print $2}') -gt 0 ]]
then find /u01/app/oracle/work/sam/backup/backup.$SAM -mtime -1 -print | xargs grep Error | while read LINE
do
FILE2=$(echo $LINE | sed 's/.* see //;s/ for details//')
echo $FILE2
[[ -f "$FILE2" ]] && tail -5 $FILE2 || echo "($FILE2 not found)"
echo $FILE2
VAR=$(echo $FILE2 | cut -c2-4)
echo $VAR
[ -f errorexists.$VAR.$SAM ] $$ "no error" > noproblems.txt || touch errorexists.$VAR.$SAM
done
else touch noerror.txt
fi
#
if /u01/app/oracle/work/sam/backup/errorexists.$VAR.$SAM -newer timelastrun.txt > /dev/null
then tail -5 $FILE2 > backerrordetails.log
else touch nada.txt
fi
#
if [[ $(cksum /u01/app/oracle/work/sam/backup/backerrordetails.log | nawk '{print $2}') -gt 0 ]]
then $ERROR2
else touch nada.txt
fi
#
touch timelastrun.txt

I get the following errors when I run the script as a whole:

./backupchk.sh[27]: test: ] missing
./backupchk.sh[32]: /u01/app/oracle/work/sam/backup/errorexists.u01.Wed: cannot execute
./backupchk.sh[38]: Error: not found

however if I run the script in sections each section seems to be working. Any help aprreciated.

Sam

 
I think you meant to use && instead of $$ on line 28.

On line 33 you are missing a find command after the if.

On line 39 you are missing an echo before the $ERROR2.

Also, in the places where you are using cksum to check for the existence of a file, a simpler syntax would be:

Code:
if [[ -s /path/to/file ]]
then
    echo "/path/to/file exists and has a size greater than 0 bytes"
fi

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top