Sample Header Ad - 728x90

Script called by another system doesn't run correctly

0 votes
1 answer
85 views
I am trying to write some scripts for graceful shutdowns from my UPS. My UPS is hooked up to my freenas system. I also have a KVM server running KVM on Ubuntu 18.04, and that is where I'm having some issues. I have the following script on my freenas to call the shutdown script on my KVM server: ssh user@192.168.1.1 /opt/shutdown.sh Then the shutdown.sh script on my KVM server is as follows #!/bin/bash # Configure timeout (in seconds). TIMEOUT=300 VIRSH=/usr/bin/virsh # List running domains. list_running_domains() { $VIRSH list | grep running | awk '{ print $2}' } echo "Try to cleanly shut down all running KVM domains..." # Create some sort of semaphore. touch /tmp/shutdown-kvm-guests # Try to shutdown each domain, one by one. list_running_domains | while read DOMAIN; do # Try to shutdown given domain. $VIRSH shutdown $DOMAIN done # Wait until all domains are shut down or timeout has reached. END_TIME=$(date -d "$TIMEOUT seconds" +%s) while [ $(date +%s) -lt $END_TIME ]; do # Break while loop when no domains are left. test -z "$(list_running_domains)" && break # Wait a litte, we don't want to DoS libvirt. sleep 1 done # Clean up left over domains, one by one. list_running_domains | while read DOMAIN; do # Try to shutdown given domain. $VIRSH destroy $DOMAIN # Give libvirt some time for killing off the domain. sleep 3 done I found the KVM script here enter link description here The KVM shutdown script works great when I SSH directly into the KVM server, however, when the freenas system calls the script over SSH it doesn't seem to work. I can see the echos, so I know it's getting called. I know it's not the best practice, but I set permissions on the script to 777 just to see if I can get it working, but that still doesn't seem to help. Any insight would be much appreciated.
Asked by DasPete (111 rep)
Oct 6, 2020, 05:28 PM
Last activity: Oct 6, 2020, 09:56 PM