- 论坛徽章:
- 0
|
本帖最后由 sc66 于 2010-02-23 02:39 编辑
#!/bin/bash
export ORACLE_HOME=/opt/oracle/oradb/home
export PATH=$ORACLE_HOME/bin:/opt/oracle/oradb/home/bin PATH
export DBTYPE=oracle
export SID=imapdb
export ip="10.71.10.57"
HOSTNAME=`hostname`
DEPARTMENT="SNO"
OS=`uname -a|awk -F" " '{print $1}'`
DELIMITER="@orz@"
ftp_server="192.168.1.99"
ftp_username="sno"
ftp_password="ams"
RUNTIME_DIR=
DATABACK="/opt/osfile/data"
LOGFILE="/opt/osfile/log"
if [ ! -d "$DATABACK" ]
then
mkdir -p "$DATABACK"
fi
if [ ! -d "$LOGFILE" ]
then
mkdir -p "$LOGFILE"
fi
sqlplus -s /nolog << EOF > "$DATABACK/oracle_user.sql"
connect sys/emsems@imapdb as sysdba
set pagesize 300;
set echo off;
set serveroutput off;
set heading off;
set termout off;
#select username,profile from dba_users;
select username,user_id,created from all_users;
exit;
EOF
if [ -f "$DATABACK/oracle_user.sql" ]
then
more /opt/osfile/data/oracle_user.sql|grep -v "select"|egrep -v "^$"|egrep [0-9]$|gawk '{print $1"@orz@"$3}'|while read var
#for var in "$(gawk '{print $1,$3}' /opt/osfile/data/oracle_user.sql |grep -v "select"|grep -v ^$)"
do
echo "$HOSTNAME$DELIMITER$OS$DELIMITER$var">>"$DATABACK/$HOSTNAME"_oracle.txt
done
else
echo "`date +%y%m%d`oracle_sql_fail">>"$LOGFILE"/"$HOSTNAME"log.txt
fi
if [ -d "$DATABACK" ]
then
cd "$DATABACK"
rm -rf *.txt
ftp -n <<EOF2 > "$LOGFILE"/"$HOSTNAME"ftp.log
open "$ftp_server"
user "$ftp_username" "$ftp_password"
cd "$RUNTIME_DIR"
ascii
prompt
mput *os*.txt
quit
EOF2
else
echo "`date +%y%m%d`log_fail">>"$LOGFILE"/"$HOSTNAME"log.log
fi |
|