# !/bin/bash
today=`date +%Y%m%d`
yesterday=`date -d "1 day ago" +%Y%m%d`
work_dir=$(pwd)
##获取、处理日志
sar -f /var/log/sa/sa15 > $work_dir/top_text.txt
chmod 755 $work_dir/top_text.txt
more $work_dir/top_text.txt | sed '1,3d' > $work_dir/top_$today.txt
chmod 755 $work_dir/top_$today.txt
sed -i 's/\ /,/g' $work_dir/top_$today.txt
## cp 文件 ####
cp -f $work_dir/top_$today.txt $work_dir/info.txt
##sqlldr imp ####
sqlldr oracle数据库用户名/oracle数据库密码 control=$work_dir/info.ctl
### create oracle table
create table top_ttt( data_date varchar2(30) , cpu1 varchar2(30) , user1 varchar2(30) , nice1 varchar2(30) , system1 varchar2(30) , iowait1 varchar2(30) , steal1 varchar2(30) , idle1 varchar2(30) );
####
vim info.ctl
load data
infile 'info.txt'
append into table top_ttt
fields terminated by ','
(
data_date,
cpu1,
user1,
nice1,
system1,
iowait1,
steal1,
idle1
)