I was able to sucessfully reboot an group of instances with
#!/bin/bash
# Get uptime in seconds
uptime_seconds=$(awk '{print $1}' /proc/uptime | cut -d. -f1)
# Check if uptime is greater than 18 hours (64800 seconds)
if [ "$uptime_seconds" -gt 64800 ]; then echo "Uptime exceeds 18 hours. Initiating reboot."
# Schedule a reboot in 5 minutes
/sbin/shutdown -r +5 "Scheduled reboot by AWS SSM Maintenance Window"
else echo "Uptime is below 18 hours. No reboot scheduled."
fi
OUTPUT: Uptime exceeds 18 hours. Initiating reboot.
ERROR: Shutdown scheduled for Tue 2024-03-19 13:20:02 UTC, use 'shutdown -c' to cancel.
Was expecting rolling reboots, 2 instances at 13:15 and the other 2 at 13:20.
Instead, what I got was a reboot 13:20 today even with that error message, however it rebooted all 4 instances at that time instead of rolling the reboots 5 minutes after each other. I have the targets set to 2 at a time under concurrency.
Not sure what's going on with my bash script here. Can someone provide me the correct script to space rebooting 5 minutes apart from each instance? or do i need to create a ssm document here with python scripting?