Skip to content

Instantly share code, notes, and snippets.

@bob454522
Created September 5, 2024 21:29
Show Gist options
  • Save bob454522/e583353128e2106f8656d703c8893638 to your computer and use it in GitHub Desktop.
Save bob454522/e583353128e2106f8656d703c8893638 to your computer and use it in GitHub Desktop.
is for crestron tsw-1070 / tss-1060 with a LED light bar - (sloppy as it uses SSHPASS) -
#!/bin/bash
#Sep 5 2024-
#
# you must set / hardcode your ssh user / pass in the vars below (SSH_USER / SSH_PASSWORD)
#
# ./sendSSHcommandCrestron.sh -i 10.5.5.178 -r 20 -g 30 -b 10
#
# set the values of REG / GREEN / BLUE LEDs above, 0-100 (100 is max brightness) (setting all to 0 will turn off led bar)
#
# add the -d flag (debug) to SHOW exact command that would be run (without it running nor SSHing into panel)
#
# if LEDs are not ON, you may have to ssh into panel and run (otherwise if they are on -r 0 -g 0 -b 0 will turn all off) :
#
# setdigitaljoin 30025 1
# setdigitaljoin 30026 1
# setdigitaljoin 30027 1
#
#
#
# Hardcoded SSH user and password (use at your own risk; consider using key-based authentication for better security)
SSH_USER="admin"
SSH_PASSWORD="XXX"
# Debug mode (set to true to only echo the commands without executing)
DEBUG=false
# Function to display usage information
usage() {
echo "Usage: $0 -i <IP_ADDRESS> -r <RED_VALUE> -g <GREEN_VALUE> -b <BLUE_VALUE>"
echo "Where <RED_VALUE>, <GREEN_VALUE>, and <BLUE_VALUE> are between 0 and 100."
exit 1
}
# Parse command-line options
while [[ $# -gt 0 ]]; do
case $1 in
-i)
IP_ADDRESS=$2
shift 2
;;
-r)
RED_VALUE=$2
shift 2
;;
-g)
GREEN_VALUE=$2
shift 2
;;
-b)
BLUE_VALUE=$2
shift 2
;;
-d)
DEBUG=true
shift 1
;;
*)
usage
;;
esac
done
# Check if all required arguments are provided and values are in range
if [ -z "$IP_ADDRESS" ] || [ -z "$RED_VALUE" ] || [ -z "$GREEN_VALUE" ] || [ -z "$BLUE_VALUE" ]; then
usage
fi
# Validate that the values are between 0 and 100
if ((RED_VALUE < 0 || RED_VALUE > 100)) || ((GREEN_VALUE < 0 || GREEN_VALUE > 100)) || ((BLUE_VALUE < 0 || BLUE_VALUE > 100)); then
echo "Error: The values for -r, -g, and -b must be between 0 and 100."
exit 1
fi
# Build the SSH command using a heredoc to send multiple commands with -t flag for pseudo-terminal allocation
SSH_COMMAND="sshpass -p \"$SSH_PASSWORD\" ssh -t -t -o StrictHostKeyChecking=no \"$SSH_USER@$IP_ADDRESS\" <<EOF
SETANALOGJOIN 33354 $RED_VALUE
SETANALOGJOIN 33355 $GREEN_VALUE
SETANALOGJOIN 33356 $BLUE_VALUE
bye
EOF"
# If debug mode is enabled, echo the command and exit
if [ "$DEBUG" = true ]; then
echo "Debug mode is ON. The command that would be run is:"
echo "$SSH_COMMAND"
exit 0
fi
# Execute the SSH command
echo "Connecting to $IP_ADDRESS with user $SSH_USER..."
eval "$SSH_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment