Now is showtime

导航

cshell 连接数据库,计算日期等的操作

最近在UNIX上写shell,要求用csh写。查了很多资料,整理了如下代码,与需要的人分享。(代码的解释等本人最近工作完成再写吧)

#!/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

posted on 2010-10-29 17:36  晨茏  阅读(431)  评论(0编辑  收藏  举报