linux轮询脚本,在linux中使用bash脚本通过轮询按键来启动和停止尾部

以下是我正在尝试做的事情,我有一个带有温度信息的arduino将通过串行方式发送到Linux盒子。我正在成功读取串行数据并将其记录到一个带有cat的文件中,然后尾随文件。很好的作品。我想在某些控件上添加广告,以便能够拖拽文件,停止拖拽但继续录制,或一起关闭该程序。所以这就是我认为我在这里成功完成的任务,但是我得到了来自linux的最奇怪的错误。我讨厌手动敲猫,我想要一个漂亮简单的小界面。我尝试了许多不同的方法来实现这些结果,并且我愿意接受新的方法。在linux中使用bash脚本通过轮询按键来启动和停止尾部

起初,当我开始我的程序中出现

./arduinodue.sh: 20: ./arduinodue.sh: [[: not found

./arduinodue.sh: 25: ./arduinodue.sh: [[: not found

以下错误,如果我按任意键此开始攻年代后或x足够的时间,我得到这个

Press S to start and stop tail

Press X to close and stop recording

最终向下滚动屏幕我的代码如下:

#!/bin/sh

#below opens serial connection

stty -F /dev/ttyACM0 cs8 19200 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

cat /dev/ttyACM0 > $HOME/Due.log & #starts cat recording serial data to Due.log as a background task

PID1=$! #records PID of cat

nottailing2() { #prints a message with instructions

echo "\n"

echo "Press S to start and stop tail\n"

echo "Press X to close and stop recording\n"

nottailing

}

nottailing() { #starts a while loop waiting for a keypress I attempted running without while loop and instead used function calls to redirect the run sequence with simular results

if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi #makes a keypress interrupt I believe but I've also attempted to run without that

while [ "x$keypress" = "x" ]; do

keypress=''

read keypress

if [[ "$keypress" == [X,x]* ]]; then #press x to kill the script cleanly

if [ -t 0 ]; then stty sane; fi

kill $PID1

exit 1

fi

if [[ "$keypress" == [S,s]* ]]; then #press s to start tail

if [ -t 0 ]; then stty sane; fi #close interrupt?

break

fi

done

if [ -t 0 ]; then stty sane; fi

tailing

}

tailing() { #same as function nottailing except it stops the tailing instead of starting it

if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi

while [ "x$keypress" = "x" ]; do

keypress=''

read keypress

if [[ "$keypress" == [X,x]* ]]; then

if [ -t 0 ]; then stty sane; fi

kill $PID1

exit 1

fi

if [[ "$keypress" == [S,s]* ]]; then

if [ -t 0 ]; then stty sane; fi

break

fi

done

if [ -t 0 ]; then stty sane; fi

nottailing2

}

nottailing2 #start the looping process

2014-10-03

Cfoote7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值