Specified bash to prevent Ubuntu syntax errors

- Changed interpreter to Bash for consistency across RedHat and Debian distros
- Added quotes to variable in sshpass command per ShellCheck

Signed-off-by: Steve Jenkins <steve@stevejenkins.com>
This commit is contained in:
Steve Jenkins
2018-03-28 20:53:48 -07:00
committed by GitHub
parent a83067b93a
commit 0e4b6a3440

View File

@@ -1,30 +1,32 @@
#!/bin/sh #!/bin/bash
#######################################################################
# A simple script for remotely rebooting a Ubiquiti UniFi access point # A simple script for remotely rebooting a Ubiquiti UniFi access point
# Version 2.2 (Mar 26, 2018) # Version 2.3 (Mar 28, 2018)
# by Steve Jenkins (http://www.stevejenkins.com/) # by Steve Jenkins (http://www.stevejenkins.com/)
#
# Requires sshpass (https://sourceforge.net/projects/sshpass/) which # Requires bash and sshpass (https://sourceforge.net/projects/sshpass/)
# is probably available via dnf, yum, or apt on your *nix distro. # which should be available via dnf, yum, or apt on your *nix distro.
#
# USAGE # USAGE
# Update the user-configurable settings below, then run ./uap_reboot.sh from # Update the user-configurable settings below, then run ./uap_reboot.sh from
# the command line. To reboot on a schedule, create a cronjob such as: # the command line. To reboot on a schedule, create a cronjob such as:
# 45 3 * * * /usr/local/bin/unifi-linux-utils/uap_reboot.sh > /dev/null 2>&1 #Reboot UniFi APs # 45 3 * * * /usr/local/bin/unifi-linux-utils/uap_reboot.sh > /dev/null 2>&1 #Reboot UniFi APs
# The above example will reboot the UniFi access point(s) every morning at 3:45 AM. # The above example will reboot the UniFi access point(s) every morning at 3:45 AM.
#######################################################################
# USER-CONFIGURABLE SETTINGS # USER-CONFIGURABLE SETTINGS
username=ubnt username=ubnt
password=ubnt password=ubnt
known_hosts_file=/dev/null known_hosts_file=/dev/null
uap_list=( 192.168.0.2 192.168.0.3 ) uap_list=( 192.168.0.2 192.168.0.3 192.168.0.4 192.168.0.5 )
# SHOULDN'T NEED TO CHANGE ANYTHING PAST HERE # SHOULDN'T NEED TO CHANGE ANYTHING PAST HERE
for i in "${uap_list[@]}" for i in "${uap_list[@]}"
do do
echo "Rebooting UniFi access point at $i..." echo "Rebooting UniFi access point at $i..."
if sshpass -p $password ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=$known_hosts_file $username@$i reboot; then if sshpass -p $password ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=$known_hosts_file $username"@$i" reboot; then
echo "Access point at $i rebooted!" 1>&2 echo "Access point at $i rebooted!" 1>&2
else else
echo "Could not reboot access point at $i." 1>&2 echo "Could not reboot access point at $i." 1>&2