Database Reference
In-Depth Information
The blackout job details can be queried with the get_blackout_details verb. The output includes a header and is tab
delimited. If the output lines are longer than the screen width, they are wrapped to the next line, as shown in Listing 3-18.
Listing 3-18. List the details of the “Blackout1” blackout
[oracle ~]$ emcli get_blackout_details -name='Blackout1'
Status Status ID Run Jobs Next Start Duration Reason Frequency Repeat Days
Started 4 no 2014-04-12 13:37:28 03:00 Testing once none none
Months Start Time End Time TZ Region TZ Offset
none 2014-04-12 13:37:28 2014-04-12 16:37:28 America/Chicago +00:00
The format above is hard to read and even harder to parse. Instead, the output could be changed to a
comma-delimited format, the header removed, and the output limited only to the columns we need, as shown
in Listing 3-19.
Listing 3-19. List the details of the “Blackout1” blackout in a format that is easier to parse
[oracle ~]$ emcli get_blackout_details \
-name='Blackout1' -noheader -format="name:csv"
Started,4,no,2014-04-12 13:37:28,03:00,Testing,once,none,none,none,2014-04-12 13:37:28,
2014-04-12 16:37:28,America/Chicago,+00:00
Once the output can be parsed, we can just test for the value we are looking for by adding the commands to a
shell script, creating the “Blackout1” target, as shown in Listing 3-20.
Listing 3-20. Create a blackout in a script and test the exit value
emcli create_blackout -name='Blackout1' -add_targets='em12cr3.example.com:host'
-schedule='frequency:once;duration:3' -reason='Testing'
MYSTATUS=$(emcli get_blackout_details -name='Blackout1' \
-noheader -format='name:csv' | cut -d ',' -f 1)
if [ "$MYSTATUS" <> "Started" ]; then
echo 'Blackout not started'
exit 1
fi
<Maintenance Script>
By using the above in your scripts, you would notice that after multiple runs it would sometimes fail and
sometimes succeed. This behavior happens because the create_blackout EM CLI verb creates but does not start the
job. The job is started by another process, so there is a chance that the blackout has not started by the time the
if statement that checks the status of the job has executed, and thus the script will fail. A solution is to use additional
shell scripting, which will either wait for the job to start before proceeding to the rest of the script or will fail because
the job stayed in “Scheduled” mode for too long, as shown in Listing 3-21.
Search WWH ::




Custom Search