how?: Interrogate print status from command line

Is it possible to interrogate octoprint from the command line to get print status details and similar information?
I want to be able to write bash/python/whatever scripts to pull simple statistics from the active octoprint instance...so it MUST be from the command prompt. ... wget/curl if necessary.

Try the CLI:

$ octoprint client --help
Usage: octoprint client [OPTIONS] COMMAND [ARGS]...

  Basic API client.

Options:
  -a, --apikey TEXT
  -h, --host TEXT
  -p, --port INTEGER
  --httpuser TEXT
  --httppass TEXT
  --https
  --prefix TEXT
  --help              Show this message and exit.

Commands:
  command         Sends a JSON command to the specified server...
  delete          Sends a DELETE request to the specified...
  get             Performs a GET request against the specified...
  listen
  patch_json      PATCHes JSON data to the specified server...
  post_from_file  POSTs JSON data to the specified server path,...
  post_json       POSTs JSON data to the specified server path.
  upload          Uploads the specified file to the specified...

Or use curl with the API.

1 Like

Thank you. This answers one part of my question. And this answers the rest.
http://docs.octoprint.org/en/master/api/job.html#retrieve-information-about-the-current-job

I was looking for similar information and wanted to provide some clarification since this is the only thread I found that got me close. I was writing a bash script to run an archive process only if the printer is offline.

The command to query job status from command line is "octoprint client get /api/job"
The returned output is a 2 line amalgamation of different information about the current job. Parse as you like for the information you need.

I've got mine piped in to a variable that looks for "Offline" in the output and returns a number:
PRINTSTATE=$(/home/pi/oprint/bin/./octoprint client get /api/job | grep -c "Offline")