If there's a "First World Problems" for scripting, this would be it.
I have the following code in a script I'm updating:
if [ $diffLines -eq 1 ]; then
dateLastChanged=$(stat --format '%y' /.bbdata | awk '{print $1" "$2}' | sed 's/\.[0-9]*//g')
mailx -r "Systems and Operations <sysadmin@[redacted].edu>" -s "Warning Stale BB Data" jadavis6@[redacted].edu <<EOI
Last Change: $dateLastChanged
This is an automated warning of stale data for the UNC-G Blackboard Snapshot process.
EOI
else
echo "$diffLines have changed"
fi
The script sends email without issues, but the mailx command is nested within an if statement so I appear to be left with two choices:
- Put
EOI
on a new line and break indentation patterns or - Keep with indentation but use something like an echo statement to get mailx to suck up my email.
I'm open to alternatives to heredoc, but if there's a way to get around this it's my preferred syntax.
awk
andsed
in the same command. Here. you could dostat … | awk '{sub(/\.[0-9]*/, ""); print $1, $2}'
, thus doing the substitution inawk
and eliminating thesed
. (Usegsub
if there is a possibility of multiple occurrences of the pattern.)