#!/bin/bash
make_decision()
{
su - oracle -c "sqlplus / as sysdba"<<EOF
select dbtimezone from dual;
EOF
echo -n `date +%Y-%m-%d-%H:%M:%S` "Do you want to modify dbtimezone?(y/n)"
read ping
while [ 1 ]
do
if [ "$ping" = "y" ];then
input_val
break
elif [ "$ping" = "n" ];then
exit 0
else
echo `date +%Y-%m-%d-%H:%M:%S` "Please input the right parameter."
echo -n `date +%Y-%m-%d-%H:%M:%S` "Do you want to modify dbtimezone?(y/n)"
read ping
fi
done
}
modify_dbtimezone()
{
#input_val
echo " "
echo -n `date +%Y-%m-%d-%H:%M:%S` "The parameter dbtimezone will be modified to $dbzone:00,are you sure?(y/n)"
read ping
while [ 1 ]
do
if [ "$ping" = "y" ];then
su - oracle -c "sqlplus / as sysdba"<<EOF
alter database set time_zone='$dbzone:00';
shutdown immediate
startup
EOF
cutPath=`pwd`
touch $cutPath/tmp.log
chmod 777 $cutPath/tmp.log
echo "select dbtimezone from dual;">$cutPath/tmp.sql
su - oracle<<EOF
sqlplus sqlplus $username/$icdpwd@$oracle_service<$cutPath/tmp.sql >$cutPath/tmp.log
EOF
val=`cat $cutPath/tmp.log -n | grep 14 | awk '{print $2}'`
su - oracle -c "sqlplus $username/$icdpwd@$oracle_service"<<EOF
update t_dbtimezone set DBTZONE = '$val';
EOF
rm $cutPath/tmp.log>/dev/null
rm $cutPath/tmp.sql>/dev/null
break
elif [ "$ping" = "n" ];then
input_val
echo " "
echo -n `date +%Y-%m-%d-%H:%M:%S`"The parameter dbtimezone will be modified to $dbzone,are you sure?(y/n)"
read ping
else
echo -n `date +%Y-%m-%d-%H:%M:%S` "Please input the right parameter:"
echo -n `date +%Y-%m-%d-%H:%M:%S` "The parameter dbtimezone will be modified to $dbzone,are you sure?(y/n)"
read ping
fi
done
}
input_val()
{
while [ 1 ]
do
echo -n `date +%Y-%m-%d-%H:%M:%S` "Please input the dbtimezone of oracle:"
read dbzone
echo $dbzone |grep ^[0-9]*$>/dev/null
var1=$?
echo $dbzone |grep ^-[0-9]*$>/dev/null
var2=$?
if [ "$dbzone" = "" ];then
echo "The parameter which you input is wrong!"
else
if [ "$var1" = 0 ] || [ "$var2" = 0 ];then
if [[ $dbzone -le 12 ]] && [[ $dbzone -gt -13 ]];then
echo " "
break
else
echo "The parameter which you input is wrong!"
fi
else
echo "The parameter which you input is wrong!"
fi
fi
done
while [ 1 ]
do
echo " "
echo -n `date +%Y-%m-%d-%H:%M:%S` "Please input oracle service name :"
read oracle_service
if [ "$oracle_service" != "" ];then
break
else
echo "Error input !"
fi
done
while [ 1 ]
do
echo -n `date +%Y-%m-%d-%H:%M:%S` "Please Input Username of uidb:"
read username
if [ "$username" != "" ];then
break
else
echo "Error input !"
fi
done
while [ 1 ]
do
echo -n `date +%Y-%m-%d-%H:%M:%S` "Please Input Password of uidb:"
read -s icdpwd
if [ "$icdpwd" != "" ];then
break
else
echo "Error input !"
fi
done
}
make_decision
modify_dbtimezone
echo 6 |grep '^[0]$\|^[-]\{0,1\}[1-9][0-9]*$' 这个是匹配整数的匹配表达式