我已经安装了 oversip 并且当我尝试从 shell 执行命令“oversip”时,
[root@vhost1111 ~]# oversip
NOTICE: <executable> OverSIP 1.3.8 starting...
它被执行了。但是当我把这个命令放到 shell 脚本中然后运行这个 shell 脚本时,它说命令未找到。
[root@vhost1111 ~]# ./init.sh start
Switch to user oversip
Starting oversip: ./init.sh: line 21: oversip: command not found
----超越路径----
[root@vhost1111 idcuser]# which oversip
/usr/local/rvm/gems/ruby-1.9.2-p320/bin/oversip
----$PATH-----
[root@vhost1111 idcuser]# echo $PATH
/usr/local/rvm/gems/ruby-1.9.2-p320/bin/oversip:
/usr/local/rvm/gems/ruby-1.9.2-p320/bin:
/usr/local/rvm/gems/ruby-1.9.2-p320@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-320/bin:
/usr/local/rvm/bin:/sbin:/bin:/usr/sbin:/usr/bin:/sbin/:/usr/bin/:/usr/sbin/:/usr/local/bin:/bin:/usr/local/sbin/:/usr/local/rvm/bin
init.sh 的内容
#!/bin/sh
PID="--pid /var/run/oversip/oversip.pid -u oversip";
if [ ! -d /var/run/oversip ]; then
mkdir -p /var/run/oversip
fi
if id -u oversip >/dev/null 2>&1; then
echo "Switch to user oversip";
else
adduser -u 106 -g 99 --shell /bin/false -b /var/run oversip
chown oversip /var/run/oversip
fi
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting oversip: "
oversip $PID
echo
touch /var/lock/subsys/oversip
;;
stop)
echo -n "Shutting down oversip ??: "
killproc oversip
echo
rm -f /var/lock/subsys/oversip
;;
status)
status oversip
;;
condrestart)
if [ -f /var/lock/subsys/oversip ]; then
$0 stop
$0 start
fi
;;
reload|restart)
$0 stop
$0 start
echo "destroy existing connections during a restart."
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
我在脚本中添加了“type oversip”和“which oversip”:下面是两者的输出。
./init.sh: line 20: type: oversip: not found
which: no oversip in (/sbin:/usr/sbin:/bin:/usr/bin)
答案1
你的初始化脚本会告诉你
which: no oversip in (/sbin:/usr/sbin:/bin:/usr/bin)
你的 shell 会告诉你
# which oversip
/usr/local/rvm/gems/ruby-1.9.2-p320/bin/oversip
您认为需要将哪个目录添加到 init 脚本的 PATH 中?
PATH="$PATH:/usr/local/rvm...320/bin"