I am trying to write a script to ssh 2 servers and get process related info. It then stores that information to a local file. This script will be called every 180 seconds. Below script is working without any errors, problem is sometimes it is producing a file of 0 kb. Am I doing something wrong here?
this is not same as Pass commands as input to another command (su, ssh, sh, etc)
as I am already using sudo in suggested way
#!/bin/bash
PATH=/usr/lib64/qt-3.3/bin:/usr/share/centrifydc/kerberos/bin:/usr/share/centrifydc/bin:/usr/share/centrifydc/kerberos/sbin:/usr/share/centrifydc/sbin:/usr/local/adtools:/sbin:/usr/sbin:/bin:/usr/bin:/opt/bmc/bladelogic/RSCD/bin:/opt/bmc/bladelogic/RSCD/sbin:/usr/local/bin:/usr/local/sbin
umask 0022
sudo -H -u genmidwp bash -c "ssh -q -T hostname1 << EOF
sudo su - bwadmin
ps -o pid -o args -C bwengine -C fix_adapter
EOF" > /opt/tibco/scripts/bwprocessout.txt 2> /dev/null
sudo -H -u genmidwp bash -c "ssh -q -T hostname2 << EOF
sudo su - bwadmin
ps -o pid -o args -C bwengine -C fix_adapter
EOF" >> /opt/tibco/scripts/bwprocessout.txt 2> /dev/null
# this is a dependent program that reads bwprocessout.txt
cd /opt/tibco/scripts
./checkEngineStatusV2.py 2> /dev/null
echo 1
exit 0