The following bash script attempts to read a file and search for the given string. in this instance, the case should generate a positive result In case of zero length, i.e. the string is not found, then send an email using Postfix (as send-only).
#!/bin/bash
results=$(grep "Parameters: {\"id_at_chain\"=>\"001142\", \"articles\"" ~/makt/current/log/production.log)
lines=($results)
if [ -z "$results" ]; then
echo "array articles 001142 missing" | mail -s "problem 001142" [email protected] [email protected]
fi
What I want to do is put some verification code in order to test (and possibly dump to a log file):
• whether the file is found
• whether $results exists
• the length of $results
I can echo $results and it gives the expected result, however
echo -z "$results" seems to output $results not the length