The UNIX and Linux Forums  
Hei og Velkommen fra USA til UNIX og Linux Forums! Takk for besøket og Delta i vårt globale samfunn.

Go Back   UNIX og Linux Forums > Top Forums > Shell programmering og Skripting
.
google unix.com



Shell programmering og Skripting Post spørsmål om ksh, csh, SH, Bash, Perl, PHP, SED, awk og ANDRE shell scripts og Shell skriptespråk her.

Mer UNIX og Linux Forum Emner Du kan finne nyttig
Tråd Tråd startet Forum Svar Siste innlegg
tcpdump og tilkobling feilsøking melanie_pfefer Red Hat 4 04-10-2008 09:17
TFTP feilsøking Bobby76 UNIX for Dummies Spørsmål og svar 0 02-29-2008 09:44
Feilsøking Samba på Solaris 8 davisr65 Sun Solaris 0 03-06-2005 01:13
Nettverk feilsøking manwithaphone UNIX for Advanced & ekspertbrukere 1 05-01-2004 08:12
Ultra10 ethernet feilsøking xyyz UNIX for Dummies Spørsmål og svar 5 03-11-2002 07:25

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Søk i denne tråden Rate Thread Visningsmoduser
  #1 (permalink)  
Old 03-04-2005
mharley mharley is offline
Registrert bruker
  
 

Bli Date: Mar 2005
Innlegg: 14
Feilsøking Script

Jeg er ganske ny på Unix (Sun OS) scripting med ksh, og jeg kunne trenge litt hjelp med feilsøking mitt script. Når jeg kjører den, får jeg feilen "hvis uventede" på funksjonen setYear. Hvis jeg kommentere ut setYear funksjonen, får jeg feilen "for uventede" på funksjonen sendEmails. Dette fører meg til å tro at feilen ligger over to funksjoner, men jeg kan ikke finne den. Jeg håper at en av dere kan være i stand til å peke meg i riktig retning. Takk på forhånd for hjelp.

Code:
#!/bin/ksh

# Author:    Mark Harley, ISDC Halifax
# Contact:   m.harley@cgi.com
# Created:   01 March 2005
# Updated:   04 March 2005
# Purpose:   This is a test of the automated monthly eBCCS log file backup.
#            The actual copies of this file are on the following servers:  

dmocnu.on.bell.ca, dmocnt.on.bell.ca, dc1c3m.qc.bell.ca

# The following files need to be backed up each month (usually on the 7th):
# Nohup.out
# PHLog.txt
# PSQTLog.txt
# Response-Log.txt
# Access.log
# Weblogic.log
# ServiceAddressQueryResponseLog.txt

# this sets the email addresses that are sent the temp file containing the command outputs
email_addresses="tina.naugler@cgi.com m.harley@cgi.com pamela.green@cgi.com"

# this puts the instance names in an array
set -A instance
instance[1]="ont0"
instance[2]="qbc1"
instance[3]="jdbc0"
instance[4]="admin1"

# this puts the file names in an array
set -A fName
fName[1]="nohup.out"
fName[2]="PHLog.txt"
fName[3]="PSQTlog.txt"
fName[4]="response-Log.txt"
fName[5]="access.log"
fName[6]="wl-domain.log"
fName[7]="weblogic.log"
fName[8]="ServiceAddressQueryResponse.Log.txt"

# these variables will contain the system date to append to the file name
# the DATEday variable can be altered for mid-month backups (but it MUST be reset to the 7th 

after backup completed)
integer DATEday=7
integer DATEmonth=$(( \( "`date +%m`" + 12 - 1 \) % 12 ))
integer DATEyear="`date +%y`"

# filler variables
zero="0"
star="*"
underscore="_"

# if the current month is January, then the backup will be for December of the previous year

function setYear{
  if [ ${DATEmonth} == 1 ]
  then
    DATEyear=${DATEyear}-1
  fi
}

# send the temp file in the body of an email to the email addresses specified above

function sendEmails{
  for email_address in $email_addresses
  do
    /bin/mail -s "${DATEday}-${DATEmonth}-${DATEyear} Log File Backup" $email_address < 

/tmp/ebccsbkup.tmp
  done
}

# backup files and compress them, then move them to the backup directory for the instance
# the results of the executed commands is written to a temp file

function backupFiles{
  for ((y=0; y<=${#fName[*]}; y++))
  do
    if [ ${fName[y]} = "access.log" ] || [ ${fName[y]} = "weblogic.log" ]; then
      if [ -f "access.log" ] || [ -f "weblogic.log" ]; then
       tar cvf bk${fName[y]}.${DATEyear}${DATEmonth}.tar ${fName[y]}.${zero}${star} >> 

/tmp/ebccsbkup.tmp
#      rm ${fName[y]}${zero}${star}
       mv bk${fName[y]}.${DATEyear}$DATEmonth.tar 

$fName[y].${DATEyear}${DATEmonth}${underscore}${DATEday}.tar >> /tmp/ebccsbkup.tmp
       gzip ${fName[y]}.${DATEyear}${DATEmonth}${underscore}${DATEday}.tar >> 

/tmp/ebccsbkup.tmp
      else
        echo "${fName[y]} does not exist in ${instance[x]}" >> /tmp/ebccsbkup.tmp
      fi
    elif [${fName[y]} = "wl-domain.log"]; then
      if [ -f "wl-domain.log" ]; then
        tar cvf ${fName[y]}.${DATEyear}${DATEmonth}${underscore}${DATEday}.tar ${fName[y]} 

>> /tmp/ebccsbkup.tmp
#       cp /dev/null/$fName[y] >> /tmp/ebccsbkup.tmp
        gzip ${fName[y]}.${DATEyear}${DATEmonth}${underscore}${DATEday}.tar >> 

/tmp/ebccsbkup.tmp
      else
        echo "${fName[y]} does not exist in ${instance[x]}" >> /tmp/ebccsbkup.tmp
      fi
    else
      if [ -f $fName[y]} ]; then
        tar cvf bk${fName[y]}.${DATEyear}$DATEmonth.tar 

${fName[y]}.${DATEyear}$DATEmonth${star} >> /tmp/ebccsbkup.tmp
#       rm ${fName[y]}.${DATEyear}${DATEmonth}${star}
       mv bk${fName[y]}.${DATEyear}$DATEmonth.tar 

${fName[y]}.${DATEyear}${DATEmonth}${underscore}${DATEday}.tar >> /tmp/ebccsbkup.
tmp
        gzip ${fName[y]}.${DATEyear}${DATEmonth}${underscore}${DATEday}.tar >> 

/tmp/ebccsbkup.tmp
      else
        echo "${fName[y]} does not exist in ${instance[x]}" >> /tmp/ebccsbkup.tmp
      fi
    fi
    echo "\n" >> /tmp/ebccsbkup.tmp
  done
  mv *.tar.gz /u01/${instance[x]}/ >> /tmp/ebccsbkup.tmp
}


# loop through the instances and call function backupFiles

function setInstance{

  # this outputs an initial statement to the temp file allowing all subsequent outputs to be 

rewrite statements
  echo "eBCCS Monthly Log Backup ${DATEday}-${DATEmonth}-${DATEyear}" > /tmp/ebccsbkup.temp

  for ((x=0; x<=${#instance[*]}; x++))
  do
    echo "${instance[x]} testing..."
    echo "\n" >> /tmp/ebccsbkup.tmp
    echo "${instance[x]} Log Files" >> /tmp/ebccsbkup.tmp
    cd /opt/bea/${instance[x]}/wls6.1/config/bles/logs
    backupFiles
  done

  sendEmails
}

setYear
setInstance
 

Hugseliste

Thread Tools Søk i denne tråden
Søk i denne tråden:

Avansert søk
Visningsmoduser Ranger denne tråden
Ranger denne tråden:

Innleggsaktivitet Regler
Du kanskje ikke poste nye tråder
Du kanskje ikke poste svar
Du kanskje ikke post vedlegg
Du kanskje ikke redigere innleggene dine

BB-kode er
Smilefjes er
[IMG] koden
HTML-koden Av
Pingbacks er
Refbacks er




Alle klokkeslett er GMT -4. Nå er klokken 06:02.


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

Content Relevant nettadresser av vBSEO 3.2.0