The UNIX and Linux Forums  
Helloやアメリカ合衆国へようこそ! UNIXおよびLinuxフォーラム!訪問し、当社のグローバルコミュニティに参加いただきありがとうございます。

Go Back   UNIXおよびLinuxフォーラム > トップフォーラム > シェルプログラミングとスクリプティング
Googleのunix.com



シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。

その他のUNIXおよびLinuxフォーラムトピックは参考にすること
スレッド スレッドスターター フォーラム 返信 最後の投稿
tcpdumpをと接続のトラブルシューティング melanie_pfefer レッドハット 4 2008年4月10日 09:17午前
TFTPのトラブルシューティング Bobby76 UNIXのダミー質問と回答のため 0 2008年2月29日 09:44午前
SambaのトラブルシューティングのSolaris 8日 davisr65 Sun Solaris 0 2005年3月6日 01:13午後
ネットワークのトラブルシューティング manwithaphone UNIXの詳細&エキスパートのためのユーザー 1 2004年5月1日 08:12午前
Ultra10イーサネットのトラブルシューティング xyyz UNIXのダミー質問と回答のため 5 2002年3月11日 07:25午後

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek を搭載 Powered by Google
 
LinkBack スレッドツール このスレッドを検索 スレッドを評価 表示モード
  #1固定リンク)  
Old 2005年3月4日
mharley mharley is offline
登録ユーザー
  
 

参加日: 2005年3月
投稿: 14
スクリプトのトラブルシューティング

私はかなりのUnix (日OS )をすると、スクリプトの新しいKsh午前、ちょっと私のスクリプトのトラブルシューティングを使用するに役立つ可能性がある。私はそれを実行するとき、私は" "この関数は、 setYearに予期しないエラーが表示される。もし私がsetYear関数をコメントアウトし、私は"のエラーが表示される"関数sendEmailsに予期しない。これは私が上記のエラーは、ある2つの機能につながると考えているが、私は見つけることができません。私はどちらかが私は正しい方向にポイントするようにできるかもしれない期待している。協力いただきありがとうございます。

コード:
#!/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固定リンク)  
Old 2005年3月4日
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
モデレータ
  
 

参加日: 2005年2月
場所:ボストン、修士
投稿数:5122
いくつかのコメント:

1 。この
コード:
set -A instance
instance[1]="ont0"
instance[2]="qbc1"
instance[3]="jdbc0"
instance[4]="admin1"
それに行うことができます:
コード:
set -A instance 'ont0' 'qbc1' 'jdbc0' 'admin1'
は同じだが他の配列宣言/初期化。
ところで、配列している ゼロベース-いない ワンベース

2 。
コード:
function setYear{
  if [ ${DATEmonth} == 1 ]
  then
    DATEyear=${DATEyear}-1
  fi
}
DATEyear整数として宣言されているなどと比較する必要があります。
コード:
if (( DATEmonth == 1 ))
と減算などとして実行する必要があります:
コード:
(( DATEyear = DATEyear -1 ))
3 。を 実際の エラー.... -のいずれかの'末尾( 'や'という新しい行( 'をするために必要な関数名の間にスペースが必要:
コード:
function setYear {

OR

function setYear
{
スクリプトでは、他の潜在的な問題ですが、ゆっくり行くよ-最初に、上記のものを修正し、出力は次のデバッグを開始します。

頑張って。
  #3固定リンク)  
Old 2005年3月4日
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unixのデーモン
  
 

参加日: 2001年8月
場所: Ashburn 、バージニア州
投稿数:9119
もう一つの問題は解決される必要がある現在、そのようなコードです:
( (イ\u003d 0 ;イ<\u003d${# fName [*]};イ+ + ) )
あなたのSolarisのバージョンを使用していると言うことはありません。のSolaris 9のように/ binに/ ksh ksh88に基づいていますし、ステートメントの演算をサポートしていません。

あなただけの演算には変わるかもしれないが。これには" y \u003d 0 "の移動手段の直前には、ループと埋め込み( (イ\u003dイ+1 ) ) 、ループの内側。 (イ+ +のいずれか)これは私が今何をすべきかと考えています。

が2番目のオプションです。 Solarisのでは/ usr / dt / binに/ dtksh dtkshが付属しています。あなたは、に切り替える可能性がある。 dtksh ksh93に基づいており、それはより高度なarithemeticを構築している。あなたdtkshのXクライアントを書くことができますが重くkshから拡張されています。これは多少は速度が低下します。

しかし、ここに何かする必要があります。あなたはksh88 intrepreterにksh93のコードを実行しようとしている。
  #4固定リンク)  
Old 2005年3月5日
muthukumar muthukumar is offline
登録ユーザー
  
 

参加日: 2005年2月
場所:コインバトール、 Tamilnadu 、インド
投稿数: 119
単純にしてデバッグするには、デバッグモードでは、 kshのスクリプトを実行すると、起動するには

ksh - xの<script.ksh>

どこになっている問題を適切な場所を与えるだろう。

あなたlik前面( (イ\u003d 0 ;としてループの) )シェルスクリプトのように一方の代わりに使用するには、イ<\u003d${# fName [*]};イ+ +に動作しないことができます

イ\u003d 0
一方[ [ $イル$ ( # fName [ * ] ) ] ]
する
行動; ;
せイ\u003dイ+1
完了した

これはトリックを行います。

HTH返答。
  #5固定リンク)  
Old 2005年3月5日
muthukumar muthukumar is offline
登録ユーザー
  
 

参加日: 2005年2月
場所:コインバトール、 Tamilnadu 、インド
投稿数: 119
私のテスト( )は、せずに、スクリプトを編集しようとした
コード:
#!/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 ###
このお試しください。 ū問題がある場合にご連絡ください。
  #6固定リンク)  
Old 2005年3月7日
mharley mharley is offline
登録ユーザー
  
 

参加日: 2005年3月
投稿: 14
更新する

[ OK ]を、すべてのご協力のおかげで、私を抱えていた問題点の多くを解決している。しかし、そのニーズに対処する新たな問題が発生している。それがワイルドカードを使用してファイルの存在を確認することは可能ですか?たとえば、 [ - f "をaccess.log $ ( 0 ) $ (星) " ] (ここで、ゼロ\u003d " 0 "と星\u003d"*")?この例では、私のすべてのファイルは、名前を"クマaccess.log0 ...".検索する元のファイル" 、 "必要なスクリプトでは無視されると、数値の接尾辞のファイルだけaccess.log tar'd移動する必要があります。私はこの構文を使用して実行しようとしており、それが検出されているファイルがなかったことが表示されます。これは別の構文の問題はあるか?すべての助けてくれてありがとう。
Closed Thread

ブックマーク

スレッドツール このスレッドを検索
このスレッドを検索

高度な検索
表示モード このスレッド
このスレッド

投稿ルール
あなた ことができない。 新しいスレッドを投稿
あなた ことができない。 返信の投稿
あなた ことができない。 添付ファイルの投稿
あなた ことができない。 自分の投稿を編集

BBコード なる 〜の上に
スマイリー なる 〜の上に
[イメージ] コードは 〜の上に
HTMLコードは、 オフ
トラックバック なる 〜の上に
ピングバック なる 〜の上に
Refbacks なる 〜の上に




すべてGMT -4です。現在の時刻は 05:21午後


提供: vBulletin、著作権© 2000 - 2006、Jelsoft企業株式会社。言語翻訳による電源
vBCredits v1.4著作権© 2007 - 2008 、 PixelFXスタジオ
は、 UNIXおよびLinuxフォーラムのコンテンツ著作権© 1993 〜 2009 。すべての権利を管理しReserved.Ad RedTyger

コンテンツ関連のURLで vBSEO 3.2.0