Bash - Running multiple commands in sequence from while loop using input from file

Wyvern1123 picture Wyvern1123 · Apr 15, 2015 · Viewed 12.4k times · Source

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.

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

Answer

Wyvern1123 picture Wyvern1123 · Apr 15, 2015

echo command to send string to at, works great.

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