cshell 连接数据库,计算日期等的操作
时间:2010-10-29 来源:天足
#!/bin/cshset ScriptPath="/export/home/oracle/test1"
set DBName="aaa"
set DBUser="bbb"
set DBPwd="ccc"
set Sys_Year=`date '+%Y'`
set Sys_Month=`date '+%m'`
echo "Begin get AC_Month---------------"
if ( ${Sys_Month} == 1 ) then
@ Sys_Year = $Sys_Year - 1
@ Sys_Month = 12
else
@ Sys_Month = $Sys_Month - 1
endif
if (${Sys_Month} < 10 ) then
set AC_Month=${Sys_Year}0${Sys_Month}
else
set AC_Month=$Sys_Year${Sys_Month}
endif
echo "AC_Month: " $AC_Month
echo "Begin get DelDate---------------"
set logon=$DBUser/$DBPwd@$DBName
set DelMonthCount=`sqlplus -s $logon @$ScriptPath/dataimport/sql/GetMonthCount.sql`
echo $DelMonthCount
if (${DelMonthCount} >= 12) then
@ Del_YearCount=$DelMonthCount / 12
@ Del_MonthCount=$DelMonthCount % 12
@ Del_Year=$Sys_Year - $Del_YearCount
@ Del_Month=$Sys_Month - $Del_MonthCount
else
if (${Sys_Month} > ${DelMonthCount}) then
@ Del_Year=$Sys_Year
@ Del_Month=$Sys_Month - $DelMonthCount
else
@ Del_Year=$Sys_Year - 1
@ Del_Month=$Sys_Month + 12 - $DelMonthCount
endif
endif
if (${Del_Month} < 10 ) then
set Del_Date=${Del_Year}0${Del_Month}
else
set Del_Date=$Del_Year$Del_Month
endif
echo "Del_Date: " $Del_Date