Bash - 使用来自文件的输入从 while 循环中按顺序运行多个命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29653138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash - Running multiple commands in sequence from while loop using input from file
提问by Wyvern1123
Trying to use a single while loop to collect variables from user and run sequential "at" commands. Singular at command works, trying to combine fails without errors. In this particular case, output shows that the jobs are created, however the first action is never completed.
尝试使用单个 while 循环从用户收集变量并运行连续的“at”命令。单点 at 命令有效,尝试组合失败而没有错误。在这种特殊情况下,输出显示作业已创建,但第一个操作从未完成。
#!/bin/bash
PATH=$PATH:/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/volmgr/bin
read -p "Enter the time and date to deactivate the policies (format - 24hr Month Date example 0400 May 09) : " offtime
read -p "Enter the time and date to reactivate the policies (format - 24hr Month Date example 0400 May 09) : " ontime
while read -r i;
do
bpplinfo $i -modify -inactive | at $offtime;
bpplinfo $i -modify -active | at $ontime
done < /tmp/policies.txt
回答by Wyvern1123
echo command to send string to at, works great.
echo 命令将字符串发送到 at,效果很好。
#!/bin/bash
PATH=$PATH:/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/volmgr/bin
read -p "Enter the time and date to deactivate the policies (format - 24hr Month Date example 0400 May 09) : " offtime
read -p "Enter the time and date to reactivate the policies (format - 24hr Month Date example 0400 May 09) : " ontime
while read -r i;
do
echo "bpplinfo $i -modify -inactive" | at $offtime;
echo "bpplinfo $i -modify -active" | at $ontime
done < /tmp/policies.txt