0

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
Tushar
  • 49
  • 3
  • this is not same as https://stackoverflow.com/questions/37586811/pass-commands-as-input-to-another-command-su-ssh-sh-etc?noredirect=1&lq=1 as I am already using sudo in suggested way – Tushar Aug 30 '18 at 09:50
  • If `ps` does not print anything, it might be, that there is neither a `bwengine` nor a `fix_adapter` process. – ceving Aug 30 '18 at 11:54
  • nope processes are running on both servers – Tushar Aug 30 '18 at 12:16

0 Answers0