r15ch13
10/23/2014 - 11:02 PM

Push a list with available linux updates to your Pusbullet Devices

Push a list with available linux updates to your Pusbullet Devices

<?php
$accessToken = "ACCESS TOKEN";
$title = "NIFTY TITLE";

$updatesText = exec("aptitude -F'%p - %V > %v' --disable-columns search '~U'", $updatesList);

if(count($updatesList) == 0) {
    exit("No updates available.");
} else {
    echo $updatesText;
}

$url = 'https://api.pushbullet.com/v2/pushes';
$data = array(
    'type' => 'list',
    'title' => $title,
    'items' => $updatesList,
);
$data = json_encode($data);
//open connection
$curl = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERPWD, $accessToken);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data)
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);

//execute post
$result = curl_exec($curl);

//close connection
curl_close($curl);