[root@limin-test ~]# cat 2.sh
#!/bin/bash
#Program:
# 修改/etc/hosts下IP及主机名地址
#定义的一些常量
log_file=/tmp/log_
HOSTNAME=`hostname`
ORACLE_TNS='/u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin'
ORACLE_SID=cpdb
HOST_IP=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
echo "修改/etc/hosts下配置信息..."
#修改IP及主机名地址
cat > /etc/hosts << EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# --- Oracle configure --- #
$HOST_IP $HOSTNAME
EOF
echo "备份原监听listener.ora及tnsnames.ora文件... "
cp $ORACLE_TNS/listener.ora -f $ORACLE_TNS/`date +%F`_listener.ora.bak
cp $ORACLE_TNS/tnsnames.ora -f $ORACLE_TNS/`date +%F`_tnsnames.ora.bak
#touch $ORACLE_TNS/listener.ora
#touch $ORACLE_TNS/tnsnames.ora
cat > $ORACLE_TNS/listener.ora << EOF
# listener.ora Network Configuration File: /u01/app/11.2.0.4/grid/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = $HOSTNAME)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
EOF
cat > $ORACLE_TNS/tnsnames.ora << EOF
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
$(echo $ORACLE_SID | tr '[a-z]' '[A-Z]') =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $HOSTNAME)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = $ORACLE_SID )
)
)
EOF
chown -R oracle:oinstall $ORACLE_TNS/listener.ora
chown -R oracle:oinstall $ORACLE_TNS/tnsnames.ora
echo " .........."
echo " ..........."
echo " ............."
echo " ...修改完成..."
echo " ....GoodBye...."