ITPub博客

首页 > Linux操作系统 > Linux操作系统 > shell常用腳本&crontab設置

shell常用腳本&crontab設置

原创 Linux操作系统 作者:tom_xieym 时间:2012-01-15 10:10:05 0 删除 编辑

shell常用腳本&crontab設置
root用戶
0,30 * * * * sh /data/run/ntp 1>/data/run/log/ntp.log 2>>/data/run/log/ntp.bad
* * * * * sh /data/run/loadavg 1>/data/run/log/loadavg.log 2>>/data/run/log/loadavg.bad

oracle用戶
15 0 * * * sh /data/run/autodel 1>>/data/run/log/autodel.log 2>>/data/run/log/autodel.bad
20 0 * * * sh /data/run/autoexp 1>/data/run/log/autoexp.log 2>/data/run/log/autoexp.bad
30 0 * * 6 sh /data/run/rmanfull.sh 1>/data/run/log/rmanfull.log 2>/data/run/log/rmanfull.bad
30 7 * * 6 sh /data/run/autostats 1>/data/run/log/autostats.log 2>/data/run/log/autostats.bad

1.同步時間(以下都是touch后,直接加入既可)
#! /bin/sh
/usr/sbin/ntpdate xxx
/sbin/hwclock -w
2.收集負載信息
# record cpu avg loading .
date >>/data/run/log/loadavg.txt
cat  /proc/loadavg >>/data/run/log/loadavg.txt

3.1.exp備份
----in windows circumstance

@echo off
set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
set mydate=%year%%month%%day%
set hhmmss=%time:~0,2%%time:~3,2%%time:~6,2%
rem if "%hhmmss:~0,1%"==" " set hhmmss=0%time:~1,1%%time:~3,2%%time:~6,2%
rem echo ------------------------------------------------ >> E:\expepd3eco\x.txt
rem echo %mydate%_%hhmmss% >> E:\expepd3eco\x.txt
rem echo ------------------------------------------------ >> E:\expepd3eco\x.txt
echo
set NLS_LANG=AMERICAN_AMERICA.AL32UTF8
exp system/"xxx" file=e:\expdata\eco_%mydate%%hhmmss%.dmp log=E:\expdata\log\eco_%mydate%%hhmmss%.log full=y

3.2 exp
----in Linux circumstance
#!/bin/sh
cd /data/expbak
ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID
NLS_LANG=american.AL32UTF8;export NLS_LANG
FILENAME=`date +%Y%m%d%H`
/u01/product/oracle/bin/exp 'system/"xxx"' file='xxx'$FILENAME full=y log=xxx$FILENAME.log

/usr/bin/gzip 'xxx'$FILENAME'.dmp'

find /data/expbak -atime +5 -exec rm -f {} \;

4.1 開機腳本
----in Linux circumstance(單機)
#!/bin/sh

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

/u01/product/oracle/bin/sqlplus /nolog <connect / as sysdba;
startup;
exit;
EOF

/u01/product/oracle/bin/lsnrctl <start
exit
EOF

雙機(10G OCFS2)
#!/bin/sh

srvctl start nodeapps -n  ecsrac01
srvctl start nodeapps -n  ecsrac02
srvctl start database -d  ecsdb
emctl  start dbconsole

5.1 關機腳本
----in Linux circumstance(單機)
#!/bin/sh

/u01/product/oracle/bin/lsnrctl <stop
exit
EOF

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

/u01/product/oracle/bin/sqlplus /nolog <connect / as sysdba;
alter system switch logfile;
/
/
shutdown immediate;
exit;
EOF

雙機
#!/bin/sh

emctl  stop dbconsole
srvctl stop database -d  ecsdb
srvctl stop nodeapps -n  ecsrac01
srvctl stop nodeapps -n  ecsrac02

6.1 重新編譯無效的包
方法一
----in Linux circumstance
#!/bin/sh

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

/u01/product/oracle/bin/sqlplus /nolog <connect / as sysdba;
@$ORACLE_HOME/rdbms/admin/utlrp.sql;
exit;
EOF

方法二  --执行计划的包
#!/bin/sh

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

/u01/product/oracle/bin/sqlplus /nolog <connect / as sysdba;
drop table plan_table;
@$ORACLE_HOME/rdbms/admin/utlxplan;
@$ORACLE_HOME/rdbms/admin/prvtspao.plb;
@$ORACLE_HOME/rdbms/admin/utlrp.sql;
exit;
EOF

6.2 重新編譯無效的包(加強版)
----in Linux circumstance
#!/bin/sh

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

/u01/product/oracle/bin/sqlplus /nolog <connect / as sysdba;
drop table plan_table;
@$ORACLE_HOME/rdbms/admin/utlxplan;
@$ORACLE_HOME/rdbms/admin/prvtspao.plb;
@$ORACLE_HOME/rdbms/admin/utlrp.sql;
exit;
EOF

7.1定時刪除日誌的
----in Linux circumstance
#!/bin/bash

find /opt/oracle/admin/smt/bdump/*.trc -mmin +4320 -exec rm -f {} \;

find /opt/oracle/admin/smt/udump/*.trc -mmin +4320 -exec rm -f {} \;

find /opt/oracle/arch1/*.dbf  -mmin  +10080  -exec rm -f {} \;

8.1 rman備份腳本
第一步 先設置crontab定時跑
第二步
#!/bin/sh

ORACLE_HOME=/opt/oracle/product/9.2.0;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

rm -f /data/rmandata/*

echo 'Recovery Manager Start at '`date`'.' >/data/run/log/rman.log
$ORACLE_HOME/bin/rman target / @'/data/run/rmanfull.sql' log /data/run/log/rman.log
echo 'Recovery Manager End at '`date`'.' >>/data/run/log/rman.log
第三步
run{
allocate channel dev1 type disk;
allocate channel dev2 type disk;
allocate channel dev3 type disk;
allocate channel dev4 type disk;
backup  full tag 'dbfull'
format '/data/rmandata/full_%d_%T_%U' database;
sql 'alter system archive log current';
release channel dev1;
release channel dev2;
release channel dev3;
release channel dev4;

allocate channel dev1 type disk;
backup
format '/data/rmandata/ctl_%d_%T_%U' current controlfile;
release channel dev1;
}

9.1 定時收集統計信息
#!/bin/sh
source /home/oracle/.bash_profile
echo 'start datetime --> ' `date`
################################################
sqlplus -S '/as sysdba' < begin
   dbms_stats.gather_schema_stats(ownname=> 'xxx' , estimate_percent=> 15 , cascade=> TRUE );
   dbms_stats.gather_schema_stats(ownname=> 'xxx' , estimate_percent=> 15 , cascade=> TRUE );
   dbms_stats.gather_schema_stats(ownname=> 'xxx' , estimate_percent=> 15 , cascade=> TRUE );
 end;
/
exit
EOFarch1

#################################################
echo 'finish datetime --> ' `date`

10.1定時跑awr
第一步
30 0 * * * sh /home/oracle/dba/awr 1>/u01/run/log/autoawr.log 2>/u01/run/log/autoawr.bad
第二步
#!/bin/sh

cd /u01/logbak
rm *.html(方法一)

ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=xxx;export ORACLE_SID

$ORACLE_HOME/bin/sqlplus /nolog<connect / as sysdba;
@/u01/run/autoawr.sql;
exit
!

find  /u01/logbak/xxx*.html  -mmin  +4320 -exec rm -f {} \; (方法二)

-------------------
待更新。。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25850100/viewspace-714940/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-05-20

  • 博文量
    77
  • 访问量
    92617