33 lines
1023 B
Bash
33 lines
1023 B
Bash
#!/bin/sh
|
|
|
|
# Host where the smart USB hub is connected
|
|
# (uhubctl must be installed on the host)
|
|
export HOST=rpi-3
|
|
export HOSTPORT=22
|
|
# Hub port where the RedPitaya is connected
|
|
export HUBPORT=4
|
|
# RedPitaya hostname and root information
|
|
export RP_HOST=rp-f0612e
|
|
|
|
# Issue shutdown on the RedPitaya
|
|
echo "Requesting shutdown on RP at $RP_HOST. Please enter password."
|
|
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password root@$RP_HOST "shutdown 0"
|
|
|
|
# Check if RedPitaya has been disconnected from network by pinging
|
|
while ping $RP_HOST -c 1 >/dev/null 2>/dev/null
|
|
do
|
|
true
|
|
done
|
|
# Print time when RedPitaya is down on network
|
|
TIMESTAMP_PRETTY=$(date '+%Y-%m-%d %H:%M:%S')
|
|
echo "RP disconnected at $TIMESTAMP_PRETTY."
|
|
# Wait 15 seconds
|
|
sleep 15
|
|
|
|
# Get power-off time & date
|
|
TIMESTAMP_PRETTY=$(date '+%Y-%m-%d %H:%M:%S')
|
|
# Power off RedPitaya connected to the smart USB hub
|
|
# (assume that only 1 hub is connected)
|
|
ssh -p $HOSTPORT $HOST "uhubctl -a off -p $HUBPORT"
|
|
echo "RP powered off at $TIMESTAMP_PRETTY."
|