【发布时间】:2020-10-05 18:33:58
【问题描述】:
我设法制作了一个脚本,它通过 minicom 发送一些命令并将它们存储在 output.txt 中。调用minicom的脚本叫做dut.sh
#!/bin/bash
echo "Setting up DUT"
stm_armv7 -print "DUT"
stm_armv7 -dut
echo "wait 30s"
sleep 30s
stty -F /dev/ttyACM0 115200 cs8 -cstopb -parenb
rm /home/fsnk/scripts/serial-com/output.txt
export TERM=linux-c-nc
minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o
echo "wait another 5s"
sleep 5s
stm_armv7 -ts
所以在minicom 命令上,我给出了另一个名为serial 的文件,其中包含一些运行脚本代码。
# UNIX login script.
# Can be used to automatically login to almost every UNIX box.
#
# Some variables.
set a 0
set b a
print Trying to Login..
# Skip initial 'send ""', it seems to matter sometimes..
send ""
goto login
login:
if a > 3 goto failed1
expect {
"ogin:" send "root"
"assword:" send ""
timeout 5 goto loop1
}
goto loop1
loop1:
send "systemctl is-system-running --wait"
sleep 3
# Send command not more than three times.
inc b
if b > 3 goto failed1
expect {
"\nrunning" goto success1
break
"degrading" goto success2
break
timeout 5 goto failed2
}
success1:
print \nSuccessfully received running!
! killall -9 minicom
exit
success2:
print \nSuccessfully received degrading!
! killall -9 minicom
exit
failed1:
print \nConnection Failed (wrong password?)
! killall -9 minicom
exit
failed2:
print \nMessage sending failed. Didn't receive anything!
! killall -9 minicom
exit
命令! killall -9 minicom 根据manual 杀死minicom 终端。正如我之前提到的,当我在本地运行它时,或者当我从本地机器通过 ssh 调用脚本时,它运行正常。当我从 jenkins 运行它时会出现问题。
output.txt 文件已创建,但在 Jenkins 上仍为空,我收到如下 minicom 消息:
Setting up DUT
wait 30s
Welcome to minicom 2.7
OPTIONS: I18n
Compiled on Apr 22 2017, 09:14:19.
Port /dev/ttyACM0, 16:30:57
Press CTRL-A Z for help on special keys
/home/fsnk/scripts/serial-com/dut.sh: line 12: 5639 Killed minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o
wait another 5s
Finished: SUCCESS
在消息Press CTRL-A Z for help on special keys 之后,我希望它登录到板(没有密码,只有root 用户)并运行systemctl is-system-running --wait。所有输出必须在 output.txt 上
同样,当手动运行或通过 SSH 从我的机器触发时,这可以正常工作,但是当从 Jenkins 触发时(添加了一个构建步骤 execute shell,它尝试 SSH 并启动脚本)它不起作用。
此时我觉得这是一个 minicom 问题,在这种情况下,我欢迎使用 screen 的任何解决方案
【问题讨论】:
标签: bash jenkins serial-port gnu-screen