简单shell的例子

一些简单的shell功能我做了个总结,给看客们做个参考:

------类型------
#! /bin/csh
------类型------

----定义变量--------
setenv ORACLE_BASE /arraybill/oracle/app/oracle
setenv ORACLE_SID cncbill
setenv ORA_NLS33 /arraybill/oracle/app/oracle/product/9206/ocommon/nls/admin/data
setenv LD_LIBRARY_PATH /arraybill/oracle/app/oracle/product/9206/lib32:/arraybill/oracle/app/oracle/product/9206/ctx/lib:/lib:/usr/l
ib:/arraybill/oracle/app/oracle/product/9206/rdbms/lib:/arraybill/oracle/app/oracle/product/9206/lib
setenv ORACLE_HOME /arraybill/oracle/app/oracle/product/9206
setenv run_path = /arraybill/app1/liuhe
setenv PATH $ORACLE_HOME/bin:/usr/bin:/etc:/usr/lbin:/usr/bin/X11:/usr/local/bin:$PATH
----定义变量--------

---时间格式定义--

set year=`date +%Y`
set month=`date +%m`
set date=`date +%d`

---时间格式定义---

cd $run_path

echo "ftp test begin ........!"


ftp -n user username/password
ascii (如果是2进制= bin)
prompt
cd /remote_dir
lcd /local_dir
get *
bye
!

echo "..........ftp test end!"

echo "sqlplus test begin .........!"

sqlplus unitele/cncacbd <> ./log/bill_ts_check.log
set head on
set linesize 321
set heading on


SPOOL ON;

SPOOL test.log

SELECT SYSDATE FROM DUAL;

SELECT c.tablespace_name,
ROUND(a.bytes/1048576,2) Megs_Alloc,
ROUND(b.bytes/1048576,2) Megs_Free,
ROUND((a.bytes-b.bytes)/1048576,2) Megs_Used,
ROUND(b.bytes/a.bytes * 100,2)||'%' Pct_Free,
ROUND((a.bytes-b.bytes)/a.bytes,2) * 100||'%' Pct_Used
FROM (SELECT tablespace_name,
SUM(a.bytes) bytes,
MIN(a.bytes) minbytes,
MAX(a.bytes) maxbytes
FROM sys.DBA_DATA_FILES a
GROUP BY tablespace_name) a,
(SELECT a.tablespace_name,
NVL(SUM(b.bytes),0) bytes
FROM sys.DBA_DATA_FILES a,
sys.DBA_FREE_SPACE b
WHERE a.tablespace_name = b.tablespace_name (+)
AND a.file_id = b.file_id (+)
GROUP BY a.tablespace_name) b,
sys.DBA_TABLESPACES c
WHERE a.tablespace_name = b.tablespace_name(+)
AND a.tablespace_name = c.tablespace_name
ORDER BY megs_free;

----执行本地脚本

@/绝对路径/test.sql;

----执行本地脚本

----定义函数

write_log()
{
_MSG=$1;
_FILE=$2;
if [ $var1=1 ]; then
echo `date +%Y/%m/%d-%H:%M:%S`" write_log error!"
return 1;
fi
echo `date +%Y/%m/%d-%H:%M:%S`": "$_MSG >> $_FILE;
}
----定义函数


---通过配置文件循环处理

foreach $var1 ={cat `test.txt`}

action.....

end ;

---通过配置文件循环处理


----判断 语句

if [ $1='var1' ]; then

exec procedure_name1({$1},{$2},{$3}.........);

elif [$1='var2' ]; then

exec procedure_name2({$1},{$2},{$3}.........);

else

exec procedure_name3({$1},{$2},{$3}.........);
fi


SELECT SYSDATE FROM DUAL;

SPOOL OFF;

EXIT

EOF

echo ".........sqlplus test end !"

[@more@]
请使用浏览器的分享功能分享到微信等