@ginganutz Did you ever make any headway here?

I am trying to do the exact thing, I wrote a bash script just like you, then I ran into the same issue with poweroff.