變更*com密碼的Shell Script


因為ERP是在HP-UX的機器上,所以以Winodws平台開發的程式必須在Unix下編譯才能正常,
因此前人以模組製作*com來自動編譯程式,如INVCOM:

#clear
echo 'now compiler Form $1.fmb....'
date
rm $INV_TOP/forms/US/$1.fmx
ls -l $1.fmb
$ORACLE_HOME/bin/f60gen module=$AU_TOP/forms/US/$1.fmb userid=APPS/123456 output_file=$INV_TOP/forms/US/$1.fmx module_type=form batch=YES compile_all=special
ls -l $1.err
ls -l $INV_TOP/forms/US/$1.fmx

但是每次只要重新CLONE到測試機後,所有的*com的密碼都要手動改正,因此寫了一個簡單
的Shell Script來自動更新密碼,程式碼如下:

#!/bin/sh
if [ $# -ne 2 ]; then  -- $#是指傳入參數的數量,-ne表示不等於
  echo "fix_pwd_com.sh "
  echo "exit with error"
  exit 1  --中斷程式並回傳1
fi

for v_file in *com  --讀取檔案
do
  cat $v_file > test.tmp  --先將檔案內容複製到temp檔
  sed  "s/$1/$2/gp" test.tmp -- $v_file     -->修改密碼
  echo "$v_file is complete"
done
rm -f test.tmp
exit 0

注意不要用sed -n,否則只會寫入有變動過的部份,不會寫入全部的內容

Oracle DB的listener.log清理