Hello People of the world,
I am trying to write a script that will allow user to failover apps between sites in bash.
Our applications are controlled by Pacemaker and I thought I would be able to write a function that would take in the necessary variables and act. Stop on one site, start on another. Once I have ssh
'd to the remote machine, I am unable to get the value of the grep
/awk
command back for the status of the application in PCS.
I am encountering a few issues, and have tried answers from stackoverflow and other sites.
- I send the
ssh
command to/dev/null 2>&1
as banners pop up on screen that unix admin have on the local user and-q
does not deal with it - Does this stop anything being returned? - when using
awk '{print \\\\\\$4}'
in the code, I get a "backslash not last character on line" error - To get round this, I tried
result=$(sudo pcs status | grep nds_$resource)
, however this resulted in a password error onsudo
- I have tried
>/dev/tty and >$(tty)
- I tried to not suppress the
ssh
(remove/dev/null 2>&1
) and put the output in variable at function call, removing theawk
from thesudo pcs status
entry.
result=$(pcs_call "$site1" "1" "2" "disable" "pmr")
echo $result | grep systemd
This was OK, but when I added | awk '{print \\\$4}'
I then got the fourth word in the banner.
Any help would be appreciated as I have been going at this for a few days now.
I have been looking at this answer from Bruno, but unsure how to implement as I have multiple sudo
commands.
Below is my strip down of the function code for testing on one machine;
site1=lon
site2=ire
function pcs_call()
{
site=$1
serverA=$2
serverB=$3
activity=$4
resource=$5
ssh -tt ${site}servername0${serverA} <<SSH > /dev/null 2>&1
sudo pcs resource ${activity} proc_${resource}
sleep 10
sudo pcs status | grep proc_$resource | awk '{print \\\$4}' | tee $output
exit
SSH
echo $output
}
echo ====================================================================================
echo Shutting Down PMR in $site1
pcs_call "$site1" "1" "2" "disable" "pmr"