在脚本中使用 nohup
时遇到问题。如果不使用 nohup
,脚本可以正常工作
开始该过程。运行时出现以下错误:
./iper.sh: line 16: syntax error near unexpected token `;'
./iper.sh: line 16: ` [Yy]*) nohup iperf -s > /dev/null 2>&1&; break;;'
这是完整的脚本:
#!/bin/bash
echo "Checking to see if Iperf is running:"
sleep 2
ps cax | grep iperf > /dev/null
if [ $? -eq 0 ]; then
echo "Iperf is running."
else
echo "Iperf is not running."
fi
sleep 2
while true; do
read -p "Press Y to start Iperf or N to exit: " yn
case $yn in
[Yy]*) nohup iperf -s > /dev/null 2>&1&; break;;
[Nn]*) exit;;
esac
done
发生了什么?
最佳答案
如果您要使用 &
终止命令并将其置于后台,也不要使用另一个分号 ;
终止它:
[Yy]*) nohup iperf -s > /dev/null 2>&1& break;;
以前
2>&1&;
关于linux - Bash 脚本检查进程是否正在运行并读取用户输入以在必要时启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18565002/