The UNIX and Linux Forums  
Hallo en welkom van de Verenigde Staten aan de UNIX en Linux Forum! Bedankt voor uw bezoek en Deelnemen aan onze wereldwijde gemeenschap.

Go Back   De Unix-en Linux Forum > Top Forums > Programmeren en Shell Scripting
.
google unix.com



Programmeren en Shell Scripting Post vragen over KSH, CSH, SH, Bash, Perl, PHP, sed, awk en andere shell scripts en shell scripting talen hier.

Meer UNIX en Linux Forum Onderwerpen Misschien vindt u Helpful
Draad Thread Starter Forum Antwoorden Last Post
tcpdump en aansluiting probleemoplossing melanie_pfefer Red Hat 4 04-10-2008 09:17
tftp probleemoplossing Bobby76 UNIX voor Dummies Questions & Answers 0 02-29-2008 09:44
Probleemoplossing Samba op Solaris 8 davisr65 SUN Solaris 0 03-06-2005 01:13 PM
Netwerken probleemoplossing manwithaphone UNIX for Advanced & Expert Gebruikers 1 05-01-2004 08:12
Ultra10 ethernet oplossen van problemen xyyz UNIX voor Dummies Questions & Answers 5 03-11-2002 07:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Zoeken in deze Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2005
mharley mharley is offline
Geregistreerde gebruiker
  
 

Join Date: Mar 2005
Posts: 14
Probleemoplossing Script

Ik ben redelijk nieuw voor Unix (Sun OS) scripting met Ksh, en ik zou kunnen gebruiken een beetje hulp oplossen van problemen met mijn script. Toen ik het uit te voeren, krijg ik de foutmelding "als onverwachte" op de functie setYear. Als ik het commentaar van de setYear functie, krijg ik de foutmelding "voor onverwachte" op de functie sendEmails. Dit brengt mij om te geloven dat de fout ligt boven de twee functies, maar ik kan het niet vinden. Ik hoop dat een van u misschien in staat zijn om mij in de goede richting. Bij voorbaat dank voor de hulp.

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
  #2 (permalink)  
Old 03-04-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Locatie: Boston, MA
Berichten: 5.121
een paar opmerkingen:

1. dit
Code:
set -A instance
instance[1]="ont0"
instance[2]="qbc1"
instance[3]="jdbc0"
instance[4]="admin1"
kan worden gemaakt met dat:
Code:
set -A instance 'ont0' 'qbc1' 'jdbc0' 'admin1'
hetzelfde geldt voor de andere array aangifte / initialisatie.
btw, arrays worden ZERObasis - niet ONEop basis van

2.
Code:
function setYear{
  if [ ${DATEmonth} == 1 ]
  then
    DATEyear=${DATEyear}-1
  fi
}
Analyseert wordt aangegeven als integer en moeten worden vergeleken als zodanig.
Code:
if (( DATEmonth == 1 ))
en aftrekken moeten worden uitgevoerd als zodanig:
Code:
(( DATEyear = DATEyear -1 ))
3. voor werkelijke fout .... - Je moet ofwel een spatie tussen de functienaam de afsluitende '(' OF je moet zetten '(' op een nieuwe regel:
Code:
function setYear {

OR

function setYear
{
er zijn nog andere mogelijke problemen met het script, maar we gaan langzaam - fix degene hierboven eerste en start debugging de output volgende.

succes.
  #3 (permalink)  
Old 03-04-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Locatie: Ashburn, Virginia
Berichten: 9.115
Er is nog een probleem dat moet nu worden aangepakt, en dat is de code als:
voor ((y \u003d 0; y <\u003d${# fName [*]}; y + +))
Je zegt niet welke versie van Solaris u gebruikt. Met ingang van Solaris 9, / bin / ksh is gebaseerd op ksh88 en het heeft geen ondersteuning voor het rekenkundig voor de verklaring.

Je kon gewoon veranderen naar een rekenkundige tijdje. Dit betekent dat het verplaatsen van de "y \u003d 0" tot vlak voor de lus en inbedding ((y \u003d y +1)) in de lus. (geen y + + een) Dit is wat ik zou doen.

Er is een tweede optie. Solaris komt met dtksh die in / usr / dt / bin / dtksh. Je zou kunnen overschakelen naar dat. dtksh is gebaseerd op ksh93 en heeft de meer geavanceerde arithemetic constructen. Het is sterk uitgebreid van ksh omdat je x cliënten kunnen schrijven in dtksh. Dit vertraagt enigszins.

Maar je moet hier iets te doen. U probeert ksh93 code draaien op een ksh88 intrepreter.
  #4 (permalink)  
Old 03-05-2005
Muthukumar muthukumar is offline
Geregistreerde gebruiker
  
 

Join Date: Feb 2005
Locatie: Coimbatore, Tamilnadu, India
Posts: 119
Om gewoon beginnen om vervolgens debug dat ksh script uitvoeren in debug mode,

ksh-x <script.ksh>

het geeft geschikte locatie waar het wordt steeds probleem.

U kunt niet werken voor aansluitnet als lik voorgrond ((y \u003d 0; y <\u003d${# fName [*]}; y + +)) in shell-script, zodat u kunt gebruiken terwijl in plaats van het als,

y \u003d 0
terwijl [[$ y-le $ (# fName [*])]]
doen
actie;;
Laat y \u003d y +1
gedaan

Zij zal dat doen truc.

HTH.
  #5 (permalink)  
Old 03-05-2005
Muthukumar muthukumar is offline
Geregistreerde gebruiker
  
 

Join Date: Feb 2005
Locatie: Coimbatore, Tamilnadu, India
Posts: 119
Ik heb geprobeerd om het script te bewerken (zonder controle) als,
Code:
#!/bin/ksh

# Variables
email_addresses="tina.naugler@cgi.com m.harley@cgi.com pamela.green@cgi.com"
set -A instance "ont0" "qbc1" "jdbc0" "admin1"
set -A fName "nohup.out" "PHLog.txt" "PSQTlog.txt" "response-Log.txt" "access.log" "wl-domain.log" "weblogic.log" "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)
DATEday=7
DATEmonth=$(( \( "`date +%m`" + 12 - 1 \) % 12 ))
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} -eq 1 ]
  then
    let DATEyear=DATEyear-1
  fi
}

# send the temp file in the body of an email to the email addresses specified above
function sendEmails {
  
  index=0
  while [[ $index -lt ${#email_addresses[*]} ]]
  do
  
    let email_address=${email_addresses[$index]}
    /bin/mail -s "${DATEday}-${DATEmonth}-${DATEyear} Log File Backup" $email_address < /tmp/ebccsbkup.tmp
    let index=index+1
    
  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 {
	
  let y=0;
  while [[ $y -lt ${#fName[*] ]] 
  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
        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
        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
        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
    let y=y+1
    
  done

  mv *.tar.gz /u01/${instance[x]}/ >> /tmp/ebccsbkup.tmp
}

# loop through the instances and call function backupFiles
function setInstance {
  echo "eBCCS Monthly Log Backup ${DATEday}-${DATEmonth}-${DATEyear}" > /tmp/ebccsbkup.temp
  let x=0
  while [[ $x -lt ${#instance[*]} ]]
  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
    let x=x+1
  done
  
  sendEmails
}

setYear
setInstance

exit 0
# END ###
Probeer dit. Laat het ons weten wanneer u probleem hebt.
  #6 (permalink)  
Old 03-07-2005
mharley mharley is offline
Geregistreerde gebruiker
  
 

Join Date: Mar 2005
Posts: 14
Update

Ok, dank aan al uw hulp heb ik opgelost veel van de problemen die ik had. Ik heb ondervonden een nieuw probleem is echter, behoeften die te maken hebben. Is het mogelijk om het bestaan van bestanden met behulp van een wildcard te controleren? Bijvoorbeeld, als [-f "nul access.log $ () $ (sterren)"] (waar nul \u003d "0" en ster \u003d"*")? In dit voorbeeld wil ik u alle bestanden die de naam "access.log0 ...". Het oorspronkelijke bestand, "access.log" dient te worden genegeerd door het script, en alleen de bestanden met de numerieke achtervoegsel moeten worden tar'd en verplaatst. Ik heb geprobeerd om het uit te voeren met deze syntax, en het lijkt dat geen van de bestanden worden gedetecteerd. Is dit een andere syntax probleem? Bedankt voor alle hulp.
Closed Thread

Bladwijzers

Thread Tools Zoeken in deze Thread
Zoeken in deze Thread:

Uitgebreid zoeken
Display Modes Beoordeel deze draad
Beoordeel deze draad:

Posting Regels
Jij mag niet Post Nieuwe threads
Jij mag niet na antwoorden
Jij mag niet post attachments
Jij mag niet bewerk uw berichten

BB code is Aan
Smilies zijn Aan
[IMG] code Aan
HTML-code is Uit
Trackbacks zijn Aan
Pingbacks zijn Aan
Refbacks zijn Aan




Alle tijden zijn GMT -4. Het is nu 07:11.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Vertalingen Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
De Unix-en Linux Forums Copyright © 1993-2009. Alle rechten Reserved.Ad Beheer door RedTyger

Content Relevante URL's door vBSEO 3.2.0