如何在redhat Linux中安装脚本程序
发布网友
发布时间:2022-04-23 04:40
我来回答
共2个回答
热心网友
时间:2022-05-07 04:32
所谓标准系统服务,应该是满足以下几条标准的后台运行程序。
1) 用 chkconfig --add 来安装,用 chkconfig --list 检查状态。
2) 用 ntsysv 来定制某个服务,是否伴随机器的启动而自动启动。
3) 在图形模式下,可以用 serviceconf 来启动、停止、重启服务。
4) 开机象系统服务那样显示 starting,关机显示 shutting down。
三、下面是具体的 dbora 脚本,在 Redhat 7.3 上通过,本人已经
验证了几十次,保证能运行。如果在您的系统不能运行,请告知。
备注:启动 lsnrctl 的时候不用 su- 而使用 su,否则失败,并且
要求使用 oracle 用户本身的 BASH_ENV。脚本开头的几个 ORA_xxx
参数都要依照实际情况写,否则会说找不到 Oracle 程序或者 pid。
DOS 格式方便发文,拷下来后请大家用 UltraEdit 转为 Unix 格式。
------------------------------------------------------------------------
#!/bin/bash
#
# /etc/rc.d/init.d/dbora
#
# Starts the dbora daemon
#
# chkconfig: 345 94 6
# description: Runs commands scheled by the at command at the time \
# specified when at was run, and runs batch commands when the load \
# average is low enough.
# processname: dbora
#
# copyright: Written by Wwashington AT smth bbs, free to distribute. \
# You must keep everything in this file, including the copyright \
# announcement. Study demo: atd & postgresql in /etc/rc.d/init.d
# Source function library.
INITD=/etc/rc.d/init.d
. $INITD/functions
# Source system profile.
if [ -r /etc/profile ] ; then . /etc/profile ; fi
ORA_SID=udb01
ORA_USER=oracle
ORA_BASE=/udb01/app/oracle
ORA_HOME=/udb01/app/oracle/proct/8.1.7
BASH_ENV=$ORA_BASE/.bashrc
test -x $ORA_HOME/bin/dbstart || exit 0
RETVAL=0
GREP_UNIX=`uname | awk '{if($1 ~ /(^SunOS|^HP-UX)/) print $1}'`
if ! [ "$GREP_UNIX" = "" ]
then
GREP_FLAG=ef
else
GREP_FLAG=efw
fi
RUNLEVEL=`runlevel | awk '{ print $2 }'`
# RUNLEVEL=6
case "$RUNLEVEL" in
3)
SH_FLAG=1
;;
4)
SH_FLAG=1
;;
5)
SH_FLAG=1
;;
*)
SH_FLAG=0
;;
esac
# Below is a debug info to display Show Flag
# echo RUNLEVEL=$RUNLEVEL , SH_FLAG=$SH_FLAG
#
# See how we were called.
#
prog="dbora"
start() {
# Check flag, if dbora already started, quit dbora
if [ ! -f /var/lock/subsys/dbora ]; then
echo -n $"Starting $prog: "
# This is the background exec which can work under
# both CLI (dbora) and GUI mode (serviceconf). We
# must forward stderr to a file or null, otherwise
# dbora won't start with a return code in GUI mode
echo ""
echo "[oralog] ----->;"
echo "Starting Oracle8i: "
echo "-------------------------------------------------------------------------"
# Please note that forward stderr(2) to /dev/null or &- means close stderr
su - $ORA_USER -c "$ORA_HOME/bin/dbstart >; /tmp/ORA-dbuplog" 2>;/dev/null
if [ $SH_FLAG -eq 1 ]; then
cat /tmp/ORA-dbuplog
fi
echo
echo "Starting TNS Listener:"
echo "-------------------------------------------------------------------------"
su $ORA_USER -c "$ORA_HOME/bin/lsnrctl start >; /tmp/ORA-lsnrlog" 2>;&-
if [ $SH_FLAG -eq 1 ]; then
cat /tmp/ORA-lsnrlog
fi
pid=`pidof -s ora_pmon_$ORA_SID`
if [ "$pid" == "" ]; then
RETVAL=1;
else
RETVAL=0;
fi
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora
echo
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
# In order to use database local cmd to keep safe,
# we use dbshut instead of simply kill ora_ proc.
# When we reboot (runlevel = 0 or 6), no verbose.
# Force remove /var/lock/subsys/dbora to activate
if [ $SH_FLAG -eq 1 ]; then
echo ""
echo "[oralog] ----->;"
echo "Shutting down TNS Listener:"
echo "-------------------------------------------------------------------------"
su $ORA_USER -c "$ORA_HOME/bin/lsnrctl stop"
else
su $ORA_USER -c "$ORA_HOME/bin/lsnrctl stop >; /dev/null"
fi
if [ $SH_FLAG -eq 1 ]; then
echo
fi
if [ $SH_FLAG -eq 1 ]; then
echo "Shutting down Oracle8i: "
echo "-------------------------------------------------------------------------"
su - $ORA_USER -c "$ORA_HOME/bin/dbshut"
else
su - $ORA_USER -c "$ORA_HOME/bin/dbshut >; /dev/null"
fi
pid=`ps -$GREP_FLAG | grep -e ora_ -e lsnr | grep -v grep | awk '{ print $2 }'`
# Show pids when shutdown failed, to see debug info
# echo $pid
if [ $pid ]; then
failure ""
else
success ""
fi
echo ""
rm -f /var/lock/subsys/dbora
return $RETVAL
}
restart() {
echo "Restarting Oracle8i and Listener: "
echo "========================================================================="
stop
start
}
reload() {
restart
}
status_ol() {
echo "Checking Oracle8i and Listener: "
echo "========================================================================="
su - $ORA_USER -c "$ORA_HOME/bin/dbstat"
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
restart
;;
condrestart)
if [ -f /var/lock/subsys/dbora ]; then
restart
fi
;;
status)
status_ol
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $?
exit $RETVAL
------------------------------------------------------------------------
caiwolf 回复于:2004-10-17 00:47:46
顶一个.:)
wwashington 回复于:2004-10-17 11:32:42
刚才的文件是 /etc/rc.d/init.d/dbora,现在补充一个 dbstat,
bash-2.05a# cat $ORACLE_HOME/bin/dbstat
GREP_UNIX=`uname | awk '{if($1 ~ /(^SunOS|^HP-UX)/) print $1}'`
if ! [ "$GREP_UNIX" = "" ]
then
GREP_FILE=/usr/xpg4/bin/grep
GREP_FLAG=ef
else
GREP_FILE=/bin/grep
GREP_FLAG=efw
fi
echo
echo "# ps -$GREP_FLAG | $GREP_FILE -e ora_ -e lsnr| grep -v grep"
echo
ps -$GREP_FLAG | $GREP_FILE -e ora_ -e lsnr| grep -v grep
echo
bash-2.05a# cat $ORACLE_BASE/.bashrc
# User specific environment and startup programs
ORA_FLAG=`echo $PATH | grep -e ^$ORACLE_BASE`
if [ "$ORA_FLAG" = "" ]; then
PATH=$ORACLE_HOME/bin:$PATH
export PATH
fi
JAVA_HOME=/usr/java/1.18
LD_ASSUME_KERNEL=2.2.5
export JAVA_HOME LD_ASSUME_KERNEL
. /usr/i386-glibc21-linux/bin/i386-glibc21-linux-env.sh追问是在终端内 运行么 ? 如果终端 连 简单的 Is 命令都 cann't found 怎么办
热心网友
时间:2022-05-07 05:50
假设这个脚本的文件名为:abc.sh,又假设被放在:/home/youname那么,你可以这么安装:
首先,用cd命令切换到对应的文件夹:cd /home/youname
再然后添加可执行权限:su root -->回车输入密码-->chomd a+x abc.sh
再执行:su -c 'abc.sh'