This week saw an interesting condition identified. As always I absolutely love a good challenge. Was happy to identify cause and come up with possible solutions.
In Commvault product you can associate scripts to perform Pre/Post operations. These happen in various stages of a backup for example.
Had a user indicate to me that they were having problems using a script to perform some such options. The script written was working fine when ran manually but when ran with Commvault would cause job failure due to exit/return code 1.
Asked for a copy of the scripts being used, and asked to see how it was being implemented. Immediately identified that they would define script in GUI and parse 2 arguments along with it.
Below is a snippet from the script in question. We can see script during execution checks if it has 2 options/arguments parsed and if so continues, however, as we can see if it doesn’t equal 2 it will exit 1.
# Validating Parameters if [ $# -ne 2 ]; then echo "Usage `basename $0` <PRE|POST> " exit 1 fi
Knowing this part of the product I immediately see a problem with this, as Pre and Post processes when executed will parse your options defined, but you also get some additional hidden options parsed. Click title below to see documentation;
As such when this script is being executed with the 2 options/arguments, it is actually getting greater then 2, thus hits the code block above and does an exit 1. Thus producing the failure of the job as expected.
- Fix up the code block in the script to account for the fact that the script needs at least 2 options (and will exceed 2).
- Write a wrapper script that will call the real script with only 2 options you want parsed. Thus not parsing the additional ones from Commvault.
#!/bin/sh # wrapper-script /path/to/real-script.sh $1 $2 exit 0
- Found an undocumented feature that you can parse an argument/option called “/suppress” to Pre/Post backup scripts as defined in GUI that will suppress the Commvault additional ones from coming into play. Note, doesn’t appear to work with Restore Pre/Post process.