원격 서버의 트랩 오류

원격 서버의 트랩 오류

SSH를 통해 원격 서버뿐만 아니라 로컬에서도 명령을 실행하는 스크립트가 있습니다. 로컬 서버에 오류가 발생하면 오류를 잡아 이메일을 보내고 스크립트를 종료할 수 있습니다. 하지만 SSH를 통해 원격 서버에 오류가 발생한 경우에는 이 방법이 작동하지 않습니다. 이를 달성하는 방법에 대한 아이디어가 있습니까?

#!/bin/bash
#
# Data Pump export of OE schema to 10.10.10.10 server
#

# trap and email errors
# add to the top of your script
f () {
   errcode=$? # save the exit code as the first thing done in the trap        function

v1="Error "
v2=$errcode
v3=" the command executing at the time of the error was "
v4=$BASH_COMMAND
v5=" on line "
v6=${BASH_LINENO[0]}
v7="$v1 $v2 $v3 $v4 $v5 $v6"
SUBJECT="ERROR - oe export"
EMAIL_LIST="me@???.com"

echo "$v7" | mailx -s "$SUBJECT" "$EMAIL_LIST"
exit $errcode  # or use some other value or do return instead
}
trap f ERR

set -e   # exit when a statement returns non-true value
set -u   # all variables must be set

# set environment variables
export ORACLE_SID=OEM
. $HOME/.oraenv

# start export
cd $HOME/oe_dir
exp userid=system/******@oem.qasrv parfile=par.txt

# compress export dump file
compress oeEXP.dmp

# send compressed dump file to DEMO server
scp oeEXP.dmp.Z [email protected]:/oracle/oem_dir

# import exp dump file into OEM2 schema on DEMO
ssh -t -t [email protected] <<'ENDSSH'
export ORACLE_SID=OEM
export ORACLE_HOME=/oracle/ora92
export PATH=$ORACLE_HOME/bin:$PATH
cd $HOME/oem_dir
uncompress oeEXP.dmp.Z   ########ERROR: out of disk space#########
imp system/******* file=oeEXP.dmp log=imp.log fromuser=oe touser=oem2 tables=\(*\) buffer=2000000
exit
ENDSSH

# remove exp dump file
/bin/rm -f $HOME/oe_dir/oeEXP.dmp.Z

편집: "oeEXP.dmp.Z" 압축을 푸는 동안 원격 서버에서 오류가 발생했습니다. 이메일을 보내고 스크립트를 종료하려면 로컬 서버에 오류 코드를 반환해야 합니다.

관련 정보