![]() |
Hej og Velkommen fra USA til UNIX og Linux Forums! Tak for dit besøg og deltager i vores globale samfund.
|
|
google unix.com
|
|||||||
| Forums | Registrer | Forum Regler | Links | Albums | FAQ | Members List | Kalender | Søgning | Dagens Stillinger | Mark Forums Read |
| Shell Programmering og Scripting Post spørgsmål om ksh, CSH, SH, Bash, Perl, PHP, SED, AWK og ANDRE shell scripts og Shell scriptsprog her. |
Mere UNIX og Linux Forum Emner du måske kan finde Helpful
|
||||
| Tråd | Thread Starter | Forum | Svar | Last Post |
| tcpdump og tilslutning fejlfinding | melanie_pfefer | Red Hat | 4 | 04-10-2008 09:17 AM |
| tftp fejlfinding | Bobby76 | UNIX for dummyer Spørgsmål & svar | 0 | 02-29-2008 09:44 AM |
| Fejlfinding Samba på Solaris 8 | davisr65 | Sun Solaris | 0 | 03-06-2005 01:13 PM |
| Networking fejlfinding | manwithaphone | UNIX for Advanced & Ekspertsøgning Brugere | 1 | 05-01-2004 08:12 AM |
| Ultra10 ethernet fejlfinding | xyyz | UNIX for dummyer Spørgsmål & svar | 5 | 03-11-2002 07:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Søg denne tråd | Rate Thread | Display Modes |
|
|
|
||||
|
Fejlfinding Script
Jeg er ret ny til Unix (Sun OS) scripting med ksh, og jeg kunne bruge lidt hjælp til fejlfinding i mit manuskript. Når jeg kører det, får jeg den fejl ", hvis uventede" på den funktion setYear. Hvis jeg udkommentere de setYear funktion, får jeg fejlen "for uventede" på den funktion sendEmails. Dette får mig til at tro, at fejlen ligger over de to funktioner, men jeg kan ikke finde det. Jeg håber, at en af jer måske kunne pege mig i den rigtige retning. På forhånd tak for hjælpen.
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
|
|
|||||
|
Der er et andet problem, der skal løses nu, og det er kode som:
til ((y \u003d 0; y <\u003d${# fName [*]}; y + +)) Du behøver ikke sige, hvilken version af Solaris, du bruger. Som for Solaris 9, / bin / ksh er baseret på ksh88, og det understøtter ikke den aritmetiske til redegørelsen. Du kan bare ændre det til et aritmetisk mens. Det betyder, at flytte "y \u003d 0" til lige før løkken og indlejring ((y \u003d y +1)) inde i løkken. (ingen y + + enten) Dette er, hvad jeg ville gøre. Der er en anden mulighed. Solaris kommer med dtksh som er i / usr / dt / bin / dtksh. Du kan skifte til det. dtksh er baseret på ksh93 og det har de mere avancerede arithemetic konstruktioner. Det er stærkt udvidet fra ksh siden kan du skrive x klienter i dtksh. Dette lægger en dæmper det lidt. Men du behøver at gøre noget her. Du forsøger at køre ksh93 kode på en ksh88 intrepreter. |
|
||||
|
Blot at begynde at fejlsøge eksekvér at ksh script i debug-mode som,
ksh-x <script.ksh> det vil give passende placering, hvor det bliver problemet. Du kan ikke arbejde for sløjfe som lik forgrunden ((y \u003d 0; y <\u003d${# fName [*]}; y + +)) i shell script, så du kan bruge, mens i stedet for det som, y \u003d 0 mens [[$ y-le $ (# fName [*])]] gøre handling;; Lad y \u003d y +1 gjort Det vil gøre det trick. HTH. |
|
||||
|
Jeg forsøgte at redigere scriptet (uden prøvning), som,
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 ###
|
|
||||
|
Opdatering
Ok, tak til alle for jeres hjælp, jeg har løst mange af de problemer, jeg var der. Jeg har mødt en ny Problemet er imidlertid, behov, der beskæftiger sig med. Er det muligt at kontrollere eksistensen af filer ved hjælp af et wildcard? For eksempel, hvis [-f "access.log $ (nul) $ (stjerne)"] (hvor nul \u003d "0", og stjerne \u003d"*")? I dette eksempel, vil jeg finde alle filer, der bærer navnet "access.log0 ...". Den oprindelige fil, "access.log" behov for at blive ignoreret af scriptet, og kun de filer med det numeriske endelsen skal tar'd og flyttes. Jeg har forsøgt at køre det med denne syntaks, og det viser sig, at ingen af filerne er fundet. Er dette en anden syntaks problem? Tak for al den hjælp.
|
![]() |
| Bogmærker |
| Thread Tools | Søg denne tråd |
| Display Modes | Bedøm denne tråd |
|
|