|
Home > Archive > Unix Shell > November 2006 > What is wrong with this script?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
What is wrong with this script?
|
|
| heprox 2006-11-16, 7:29 am |
| I keep getting errors messages for the "else" statement at line 81?
[CODE]
#!/bin/ksh
######### Environment Setup #########
PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac
:/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge
rs/nurev/custom:/gers/nurev/fix:/gers/nurev/src_rev/fix:/gers/nurev/opt/path:/ge
rs/nurev/bin:/g/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:.
ORACLE_HOME=/gers/nurev
ORACLE_SID=nurev
export PATH
export ORACLE_HOME
export ORACLE_SID
########## Global Variables ##########
DATE=$(date +%m%d%y)
TIME=$(date +%H%M)
DatafilesDir="/gers/nurev/datafiles"
PrintDir="/gers/nurev/print"
TempDir="/gers/nurev/tmp"
Logfile="/tmp/test_str_process_$DATE.log"
########## Function to Verify File is Completely Uploaded ###########
# Function : is_file_arrived file
# Arg(s) : file = file to verify
# Output : None
# Status : 0 = yes file arrived, 1 = no
# Env. : IFA_WAIT : interval (secs) for file size check (def=5)
#
is_file_arrived() {
[ -z "$1" ] && return 1
local file=$1
local arrived=1
local size1 size2
if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
sleep ${IFA_WAIT:-5}
size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
[ ${size1:-1} -eq ${size2:-2} ] && arrived=0
fi
log_it "Arrived is $arrived"
return $arrived
}
######### GERS Processing of File ###########
processFile ()
{
local fileName=$1
local fileExtension=$2
local fileNewName="$DatafilesDir/str${fileExtension}.asc"
local fileODIName="str${fileExtension}.pos"
mv -Eignore $fileName $fileNewName
prepup $fileNewName $fileExtension
mv -Eignore $PrintDir/$fileODIName $TempDir/$fileODIName
save2tmp $fileExtension
call_siu $fileExtension
log_it "Store file $fileName processed at $TIME on $DATE"
}
########## Log File Function ###########
log_it()
{
printf "%s\n" "$*" >> "$Logfile"
}
########## Main Processing ###########
nsec=1
while [[ "$(date +%H%M)" -lt 2340 ]]
do
for fileName in
$DatafilesDir/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]
do
fileExtension=${fileName#*.}
is_file_arrived "$fileName"
if $arrived = 0 then
if [ ! -f "$TempDir/poll_$fileExtension.txt"] then
nsec=1
processFile $fileName $fileExtension
else
log_it "Store $fileExtension is already in process"
fi
else
log_it "Store file $fileName not done uploading at $TIME on
$DATE"
fi
done
sleep $nsec
case $nsec in
1) nsec=15;;
15) nsec=45;;
45) nsec=90;;
90) nsec=300;;
300) nsec=600;;
*) nsec=900;;
esac
done
[/CODE]
| |
| Chris F.A. Johnson 2006-11-16, 7:29 am |
| On 2006-11-16, heprox wrote:
> I keep getting errors messages for the "else" statement at line 81?
Which is line 81? With the badly wrapped lines it is hard to tell.
> [CODE]
> #!/bin/ksh
> ######### Environment Setup #########
> PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac
>:/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge
> rs/nurev/custom:/gers/nurev/fix:/gers/nurev/src_rev/fix:/gers/nurev/opt/path:/ge
> rs/nurev/bin:/g/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:.
> ORACLE_HOME=/gers/nurev
> ORACLE_SID=nurev
> export PATH
> export ORACLE_HOME
> export ORACLE_SID
>
> ########## Global Variables ##########
> DATE=$(date +%m%d%y)
> TIME=$(date +%H%M)
Dont't use two calls to date. It's slow, and you may get
inaccurate values if the script is executed shortly before
midnight.
eval "$(date +'DATE=%m%d%y TIME=%H%M')"
> DatafilesDir="/gers/nurev/datafiles"
> PrintDir="/gers/nurev/print"
> TempDir="/gers/nurev/tmp"
> Logfile="/tmp/test_str_process_$DATE.log"
>
>
> ########## Function to Verify File is Completely Uploaded ###########
> # Function : is_file_arrived file
> # Arg(s) : file = file to verify
> # Output : None
> # Status : 0 = yes file arrived, 1 = no
> # Env. : IFA_WAIT : interval (secs) for file size check (def=5)
> #
>
> is_file_arrived() {
> [ -z "$1" ] && return 1
> local file=$1
> local arrived=1
> local size1 size2
Which ksh are you using? If it's ksh93, local has no effect.
> if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
> size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
> sleep ${IFA_WAIT:-5}
> size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
> [ ${size1:-1} -eq ${size2:-2} ] && arrived=0
> fi
> log_it "Arrived is $arrived"
> return $arrived
>
> }
>
> ######### GERS Processing of File ###########
>
> processFile ()
> {
> local fileName=$1
> local fileExtension=$2
> local fileNewName="$DatafilesDir/str${fileExtension}.asc"
> local fileODIName="str${fileExtension}.pos"
> mv -Eignore $fileName $fileNewName
> prepup $fileNewName $fileExtension
> mv -Eignore $PrintDir/$fileODIName $TempDir/$fileODIName
> save2tmp $fileExtension
> call_siu $fileExtension
> log_it "Store file $fileName processed at $TIME on $DATE"
> }
>
> ########## Log File Function ###########
> log_it()
> {
> printf "%s\n" "$*" >> "$Logfile"
>
> }
>
>
> ########## Main Processing ###########
>
> nsec=1
> while [[ "$(date +%H%M)" -lt 2340 ]]
There's no need for non-portable syntax.
while [ "$(date +%H%M)" -lt 2340 ]
> do
> for fileName in
> $DatafilesDir/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]
> do
> fileExtension=${fileName#*.}
> is_file_arrived "$fileName"
> if $arrived = 0 then
> if [ ! -f "$TempDir/poll_$fileExtension.txt"] then
You need a space before ']'.
> nsec=1
> processFile $fileName $fileExtension
> else
> log_it "Store $fileExtension is already in process"
> fi
> else
> log_it "Store file $fileName not done uploading at $TIME on
> $DATE"
> fi
> done
> sleep $nsec
> case $nsec in
> 1) nsec=15;;
> 15) nsec=45;;
> 45) nsec=90;;
> 90) nsec=300;;
> 300) nsec=600;;
> *) nsec=900;;
> esac
> done
> [/CODE]
>
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| PDreyer 2006-11-16, 7:29 am |
|
On Nov 16, 10:40 am, "heprox" <sdr0...@yahoo.com> wrote:
> I keep getting errors messages for the "else" statement at line 81?
>
> [CODE]
--- snip,snip ---
> nsec=1
> while [[ "$(date +%H%M)" -lt 2340 ]]
> do
> for fileName in
> $DatafilesDir/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]
> do
> fileExtension=${fileName#*.}
> is_file_arrived "$fileName"
> if $arrived = 0 then
> if [ ! -f "$TempDir/poll_$fileExtension.txt"] then
> nsec=1
> processFile $fileName $fileExtension
> else
> log_it "Store $fileExtension is already in process"
> fi
> else
> log_it "Store file $fileName not done uploading at $TIME on
> $DATE"
> fi
--- snip, snip ---
the if statement has no ; or newline before then
| |
| BobbyH 2006-11-21, 7:21 pm |
| The line <if [ ! -f "$TempDir/poll_$fileExtension.txt"] then > should have a
semicolon ; between the closing square bracked and "then".
It would also work if the "then" is on another line.
"PDreyer" <petrus.dreyer@gmail.com> wrote in message
news:1163668615.190745.110990@h54g2000cwb.googlegroups.com...
>
>
> On Nov 16, 10:40 am, "heprox" <sdr0...@yahoo.com> wrote:
> --- snip,snip ---
> --- snip, snip ---
>
> the if statement has no ; or newline before then
>
|
|
|
|
|