There are two issues I see here:
- Unless you absolutely don't trust the security of cURL, you should be running this as root, not a regular user. That will allow you to get rid of the
sudo usage, which will make things easier to debug (and may make it just work without needing any other changes).
- As a general rule, it's bad form to use the
init command to issue a reboot.
reboot is the universal option that will work on pretty much all Linux and other UNIX systems, and
shutdown -r now is the preferred method on Linux in general. You might also try
systemctl reboot since Ubuntu 16.04 uses systemd as it's init system.
If you fix both of those issues, then you should only have to worry about the Linode API and your
grep expression working together.
Also, not really an issue, but the conventional form in most cases for an
if statement in a POSIX shell script is:
if [ <condition ] ; then
if [ <conditon> ]
then <do something>
In most modern shells, the
then actually isn't needed at all and is just present to make things look nicer, but it's usually kept because there are some shells that do actually need it. This shouldn't impact how your program runs at all, it's just a style convention used by most people who use shell script (so you may get odd looks for using the second form, and will almost always see the first form in example code).