[英]Bash Script execute commands from a file but if cancel on to jump on next one
制作脚本以执行文件中的一组命令
例如,该文件有一组3个命令,分别是perl脚本-a,perl脚本-b,perl脚本-c,每个命令都换行,而我制作了此脚本
#!/bin/bash
for command in `cat file.txt`
do
echo $command
perl $command
done
问题是某些脚本卡住或完成时间太长,我想查看它们的输出。 如果我在执行的当前命令上发送CTRL + C以跳转到txt文件中的下一个命令而不取消wole bash脚本的情况下,可以制作bash脚本。
谢谢
您可以使用trap 'continue' SIGINT
来忽略Ctrl + c :
#!/bin/bash
# ignore & continue on Ctrl+c (SIGINT)
trap 'continue' SIGINT
while read command
do
echo "$command"
perl "$command"
done < file.txt
# Enable Ctrl+c
trap SIGINT
另外,您无需调用cat
即可读取文件的内容。
#!/bin/bash
for scr in $(cat file.txt)
do
echo $scr
# Only if you have a few lines in your file.txt,
# Then, execute the perl command in the background
# Save the output.
# From your question it seems each of these scripts are independent
perl $scr &> $scr_perl_execution.out &
done
您可以检查每个输出,以查看命令是否按预期执行。 如果不是,则可以使用kill
终止每个命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.