I am trying to process a bash script on a local machine but where some of the variables are needed from a remote machine (on the same LAN) via SSH. Here’s where I’ve go to s far, but it is getting the variabales where I’m stuck. How to I script to login via SSH to retrieve the variables shown below. Many thanks.
#!/bin/sh
MAX_TEMP_CPU=80
MAX_TEMP_24=60
MAX_TEMP_5=60
# Email settings (mail envelope) #
FROM_ADDRESS="someaddress"
TO_NAME="name"
TO_ADDRESS="address"
# Email credentials #
USERNAME="email"
PASSWORD="password"
# Server settings #
SMTP="smtp.gmail.com"
PORT="465"
# FROM Name in email #
FROM_NAME="Router $(nvram get productid)"
# set environment PATH to system binaries #
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
# get these variables from remote server via SSH i.e., ssh user@IPaddress password #
wifi24_status=$(nvram get wl0_ifname)
wifi5_status=$(nvram get wl1_ifname)
cpu_temp=$(cat /sys/class/thermal/thermal_zone0/temp | sed 's/[^0-9]//g' | awk '{print int( $1 / 1000 +0.5)}')
wifi24_temp=$(wl -i $wifi24_status phy_tempsense | awk '{print int($1 / 2 + 20 +0.5)}')
wifi5_temp=$(wl -i $wifi5_status phy_tempsense | awk '{print int($1 / 2 + 20 +0.5)}')
# end remote server shell connection #
if [ $cpu_temp -gt $MAX_TEMP_CPU -o $wifi24_temp -gt $MAX_TEMP_24 -o $wifi5_temp -gt $MAX_TEMP_5 ]; then
msg="Temperature too hot, CPU: $cpu_temp/$MAX_TEMP_CPU DegC 2.4Ghz wifi: $wifi24_temp/$MAX_TEMP_24 DegC 5Ghz wifi: $wifi5_temp/$MAX_TEMP_5 DegC"
# notify Syslog of the event
#logger $msg
# assemble the message
echo "From: "$FROM_NAME" <$FROM_ADDRESS>" > /tmp/mail.txt
echo "To: "$TO_NAME" <$TO_ADDRESS>" >> /tmp/mail.txt
echo "Subject: $msg" >> /tmp/mail.txt
echo "Date: $(date -R)" >> /tmp/mail.txt
echo "" >> /tmp/mail.txt
echo "--- " >> /tmp/mail.txt
echo "Your friendly home router $(nvram get productid)." >> /tmp/mail.txt
# send with curl
curl --url smtps://$SMTP:$PORT
--mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS"
--upload-file /tmp/mail.txt
--ssl-reqd
--user "$USERNAME:$PASSWORD"
# remove temp file
rm /tmp/mail.txt
fi