su - oracle
cd /u01/app/oracle/agent/agent_inst/bin
./emctl status agent
cat <<-'EOF' > restart_em_agent.sh
#!/bin/bash
HOSTMEI=$1
echo "[$(date '+%Y/%m/%d %H:%M:%S')] job start" | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
ssh ${HOSTMEI} "sudo su - oracle -c '/u01/app/oracle/agent/agent_inst/bin/emctl stop agent'" 2>&1 | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
RET=$?
if [ ${RET} -ne 0 ] ; then
echo "[$(date '+%Y/%m/%d %H:%M:%S')] em stop error( ${RET} )" | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
exit 100
fi
ssh ${HOSTMEI} "sudo su - oracle -c '/u01/app/oracle/agent/agent_inst/bin/emctl start agent'" 2>&1 | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
RET=$?
if [ ${RET} -ne 0 ] ; then
echo "[$(date '+%Y/%m/%d %H:%M:%S')] em start error( ${RET} )" | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
exit 100
fi
echo "[$(date '+%Y/%m/%d %H:%M:%S')] job end" | tee -a /tmp/restart_em_agent_$(date '+%Y%m').log
exit 0
EOF
cat restart_em_agent.sh
chmod +x restart_em_agent.sh
./restart_em_agent.sh mmm114
cat /tmp/restart_em_agent_$(date '+%Y%m').log