![]() |
Hello and Welcome-tól az Egyesült Államokat, hogy az UNIX és Linux Forums? Köszönjük, hogy meglátogatta és csatlakozik Globális Közösség.
|
|
google unix.com
|
|||||||
| Fórumok | Regisztráció | Fórum Szabályok | Linkek | Albumok | GYIK | Tagok listája | Naptár | Keres | Mai hozzászólások | Megjelöl Fórumok Olvas |
| Shell programozás és Scripting Post kérdések KSH, CSH, SH, Bash, Perl, PHP, SED, AWK ÉS EGYÉB shell szkriptek és shell script nyelvek itt. |
Több, UNIX és Linux fórum témák Ön által talált Hasznos
|
||||
| Szál | Thread Starter | Fórum | Válaszok | Utolsó hozzászólás |
| tcpdump és csatlakozási hibaelhárítás | melanie_pfefer | Red Hat | 4 | 04-10-2008 09:17 AM |
| tftp hibaelhárítás | Bobby76 | A UNIX a dummies Kérdések és válaszok | 0 | 02-29-2008 09:44 AM |
| Hibaelhárítás Samba a Solaris 8 | davisr65 | SUN Solaris | 0 | 03-06-2005 01:13 PM |
| Hálózat Hibaelhárítás | manwithaphone | A UNIX a fejlett és szakértői Felhasználók | 1 | 05-01-2004 08:12 AM |
| Ultra10 ethernet hibaelhárítás | xyyz | A UNIX a dummies Kérdések és válaszok | 5 | 03-11-2002 07:25 PM |
![]() |
|
|
LinkBack | Téma eszközök | Keresés a téma | Rate Thread | Megjelenítési módok |
|
|
|
||||
|
Hibaelhárítás Script
Én viszonylag új a Unix (Sun OS) scripting KSH-val, és jól jönne egy kis segítség hibaelhárítási my script. Mikor ÉN fuss ez, ÉN kap a hiba ", ha váratlan" a funkció setYear. If I comment setYear ki a funkciót, ÉN kap a hiba "a váratlan" a funkció sendEmails. Ez azt jelenti, hogy higgyek, hogy a hiba fölött fekszik a két funkció, de nem találom. Remélem, hogy az egyik meg tudna mutatni nekem a helyes irányba. Thanks in advance for the help.
Kód:
#!/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
|
|
|||||
|
Van egy másik probléma, hogy foglalkozni kell most, és ez a kód például:
for ((y \u003d 0, y <\u003d${# fname [*]}; y + +)) Nem mondod melyik változat a Solaris használsz. Mint a Solaris 9, / bin / ksh alapul ksh88, és nem támogatja a számtani a nyilatkozatot. Lehet, hogy csak cserél egy aritmetikai közben. Ez azt jelenti, amellyel a "y \u003d 0"-hoz csak mielőtt a hurok és beágyazás ((y \u003d y 1)) belül a hurok. (no y + + vagy) Ez az, amit szeretnék csinálni. Van egy másik lehetőség. Solaris jön dtksh, amely a / usr / dt / bin / dtksh. Lehet, hogy váltani. dtksh alapul ksh93, és azt a fejlettebb arithemetic konstrukció. Ez nagy mértékben terjesztették ki, mivel a ksh írhatunk x ügyfelek dtksh. Ez lassítja le valamelyest. De amit tenned kell valamit. Ön próbál futtatni ksh93 kódot egy ksh88 intrepreter. |
|
||||
|
Egyszerűen elkezdenek debug majd végre az ksh script debug módban,
KSH-x <script.ksh> Ezáltal megfelelő helyre, ahol egyre probléma. Nem tud dolgozni, mint hurok lik előtérbe ((y \u003d 0, y <\u003d${# fname [*]}; y + +)) a szkript úgy, hogy közben is használhatja ahelyett, hogy azt, y \u003d 0 while [[$ y-le $ (# fname [*])]] tesz keresetet;; let y \u003d y 1 kész Fog tenni, hogy a trükk. HTH. |
|
||||
|
Megpróbáltam szerkeszteni a script (vizsgálat nélkül), mint,
Kód:
#!/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 ###
|
|
||||
|
Frissítés
Ok, hála az összes segítséget, már megoldódott számos olyan problémát, amelynek én voltam. Találkoztam egy új probléma azonban az, hogy az igények kezelése. Van-e lehetőség meglétének ellenőrzése fájlokat helyettesítő? Például, ha a [-f "$ (access.log nulla) $ (csillag)"] (ahol nulla \u003d "0" és a csillag \u003d"*")? Ebben a példában akarom tudni, hogy az összes fájl nevével ellátott "access.log0 ...". Az eredeti fájl, "access.log" kell figyelmen kívül hagyja a forgatókönyvet, és csak a fájlokat a numerikus utótagot kell tar'd és mozgott. Nekem van próbált-hoz fuss ez ezzel a kódokat, és úgy tűnik, hogy a fájlok egyike sem mutatható ki. Ez egy szintaxis probléma? Köszönet minden segítségért.
|
![]() |
| Könyvjelzõk |
| Téma eszközök | Keresés a téma |
| Megjelenítési módok | Rate this thread |
|
|