4

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
hlovdal
  • 26,565
  • 10
  • 94
  • 165
Wyvern1123
  • 83
  • 1
  • 1
  • 6
  • Thanks kojiro, I was just fixing that code format...and you beat me to it – Wyvern1123 Apr 15 '15 at 14:41
  • 1
    Unless `bpplinfo` prints out the command you want executed, you need to pass it as text on standard input, not run it. Try `echo "bpplinfo $i -modify -inactive" | at $offtime` or `at $offtime <<<"bpplinfo $i ..."` – Kevin Apr 15 '15 at 14:48
  • bpplinfo is the command, its path is in the beginning of the script. It does work if I run the single line, bpplinfo $i -inactive | at $offtime, but not when the second is added. This would just be handier than running 2 scripts, one to deactivate, one to activate. – Wyvern1123 Apr 15 '15 at 14:53
  • If `bpplinfo` is the command that activates and de-activates the policies then your script isn't working because it is running both of those immediately (and `at` isn't doing anything). You need to send `at` the command *as a string* on standard input `echo "bpplinfo ..." | at $offtime` or similar. – Etan Reisner Apr 15 '15 at 14:57
  • ahhhhh, Thanks for the clarification Etan, and thanks Kevin!! – Wyvern1123 Apr 15 '15 at 15:01
  • @Wyvern1123 Please consider writing your fixed code as an answer to your own question. – dg99 Apr 15 '15 at 15:39

1 Answers1

4

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
Wyvern1123
  • 83
  • 1
  • 1
  • 6