So I'm working on a script to collect information from various VMware servers. As part of that script, I'd like to output a header section to the log that lists each of the servers that will be queried.
This command works just fine if I run it from the bash CLI as vi-admin:
Code:
vifp listservers | awk -F'\t' '{ print $1 }
However, it breaks when I put it in a script that is run by root and try to su to vi-admin. Like this:
Code:
echo "Vmware: "`su - vi-admin -c "vifp listservers | awk -F'\t' '{ print $1 }'"`
It throws an error about $1 being an unbound variable. I assume that this has something to do with awk not being run in a terminal session, causing $1 to not be stdin. I just can't work out the fix.
Any help would be much appreciated. I've spent most of the day working on this one echo statement.
Thanks!