[英]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.