I am setting up two servers: server 1 and server 2. I have written a script which runs on server 1 and saves the output to answer.txt file now I want the same script to run on server 2 and save the output to same file. We use key based login to login from one server to other .
Script destination :- /healthcheck.sh
output file :- /answer.txt
Crontab :-
* * * * * /healthcheck.sh &>> /answer.txt
I am able to run script on server 1 but not able to figure out a way to save output on same file.
#!/bin/sh
hostname
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
systemctl status squid|grep Active
I want the answer of both servers in same file.
ssh -i Key_location.pem host@server '( ~/healthcheck.sh )' >>/answer.txt
healthcheck.sh has to be saved in home directory of the host.