gpt4 book ai didi

Bash - 使用来自文件的输入从 while 循环中按顺序运行多个命令

转载 作者:行者123 更新时间:2023-11-29 09:14:01 27 4
gpt4 key购买 nike

尝试使用单个 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

最佳答案

将字符串发送到 at 的 echo 命令,效果很好。

#!/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

关于Bash - 使用来自文件的输入从 while 循环中按顺序运行多个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29653138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com