0

I am developing a PHP monitoring platform and I found this post. It works very well and I would like to do the same for an apt-get update. Is it possible to check if there are system updates available with PHP? I have no idea how to deal with the output of apt-get update.

  • Try and after ask a better question, with your solution provided. – Alberto Favaro Sep 04 '18 at 07:57
  • You can capture the output of apt the same way the answers in the post you mentioned do. The problem would be that you have to parse the output, because I think apt doesn't return non-0 if no updates are available, because the check on a system level stays successful. For the parsing you could use sed or perl/php itself. – ovm Sep 04 '18 at 08:01
  • as far as I know, this is not possible in PHP. This has to be done through commands in your console. How ever you could write a cronjob for this. Information: https://askubuntu.com/questions/923535/schedule-apt-get-script-using-cron – Ronnie Oosting Sep 04 '18 at 08:24

1 Answers1

0
        $o  = `apt list --upgradable`;
        $upgratable = explode("\n", $o);
        $l = count($upgratable);
        $u = [];
        for($i=1; $i<$l-1; $i++){
            $u[substr($upgratable[$i],0,strpos($upgratable[$i], ' '))] = substr($upgratable[$i],strpos($upgratable[$i], ' '));

        }
        dump($u);


// btw
//        pingAddress('https://stackoverflow.com'); // The IP address, https://stackoverflow.com, is dead
//        pingAddress('127.0.0.1'); // The IP address, 127.0.0.1, is dead
TsV
  • 629
  • 4
  • 7