【发布时间】:2014-11-18 09:40:37
【问题描述】:
我在 rc.local 中放置了一个指向我的脚本的链接,以便在 linux debian 启动时自动启动它。它开始然后在 while 循环处停止。这是一个 netcat 脚本,永久监听 4001 端口。
echo "Start"
while read -r line
do
#some stuff to do
done < <(nc -l -p 4001)
当我使用命令 ./myscript 以 root 身份启动此脚本时,它可以 100% 正确运行。需要 nc (netcat) 根级访问权限或其他什么?
编辑:
rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/etc/samba/SQLScripts
exit 0
rc.local 启动我的脚本“SQLScripts”
SQLScripts
#! /bin/sh
# The following part always gets executed.
echo "Starting SQL Scripts" >> /var/log/SQLScriptsStart
/etc/samba/PLCCheck >> /var/log/PLCCheck &
“SQLScripts”启动“PLCCheck”(仅举例)
PLCCheck
#!/bin/bash
echo "before SLEEP" >> /var/log/PLCCheck
sleep 5
echo "after SLEEP" >> /var/log/PLCCheck
echo "vor While" >> /var/log/PLCCheck
while read -r line
do
echo "in While" >> /var/log/PLCCheck
done < <(netcat -u -l -p 6001)
【问题讨论】: