-2

While I've set up a cron job like planning a reboot when a Kernel update is available using Linode API

curl -s https://api.linode.com/v4/linode/kernels/linode/latest-64bit | grep "Latest.*$(uname -r)" > /dev/null
if [ $? -eq 1 ]
then sudo init 6
fi

More changes please review grep command

my uname -r output 4.14.12-x86_64-linode92 also compare with Linode API

curl -s https://api.linode.com/v4/linode/kernels/linode/latest-64bit | grep "Latest 64 bit *$(uname -r)" > /dev/null
if [ $? -eq 1 ]  ; then

systemctl reboot fi

0

There are two issues I see here:

  1. 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).
  2. 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
    <do something>
fi

and not:

if [ <conditon> ]
then <do something>
fi

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).

  • Thanks a lot for info but please review my new crontab code and correct that code.. – Gopal Raha Jan 16 '18 at 20:38
  • I need help about implement these cron job script in my Ubuntu distro please check above code whether it is correct or not i mean 100% working script. – Gopal Raha Jan 18 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.