How to check is printer on / offline with CUPS?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















We have some windows box on the network, and shared printers on them.



I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:



exec('lp -d vasosamsung file.pdf');


Cool. I worte a Printer class, what makes some validation before the print job ccould start.



The first thing what I check is the printer is exists:



lpstat -p vasosamsung


If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.



If the answer is idle, or printing, the everything is fine, let's send the job.



BUT!



The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.



Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).



The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart, and get a stat:



printer vasosamsung is idle.  enabled since Thu 06 Apr 2017 03:34:26 PM CEST


It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:



string(40) "request id is vasosamsung-71 (1 file(s))"


and the job is on the web interface:



vasosamsung-71  Unknown     Withheld    1933k   1   held since


Thu Apr 6 15:59:43 2017



My question is: is there a way ti get the phisicaly printer status? Offline, printing etc... not from CUPS?



If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?



EDIT



Hehe, when I turned off my machine, the printer is idle also :)



I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.










share|improve this question

























  • Cant stop laughing. It is lying :-)

    – A Umar Mukthar
    Apr 6 '17 at 14:18











  • @AUmarMukthar First I thought that. I changed the name of question, but you were right.

    – vaso123
    Apr 6 '17 at 14:22











  • If the driver does not support it you won't be able to.

    – Rinzwind
    Apr 6 '17 at 14:38











  • How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

    – vaso123
    Apr 6 '17 at 14:42


















0















We have some windows box on the network, and shared printers on them.



I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:



exec('lp -d vasosamsung file.pdf');


Cool. I worte a Printer class, what makes some validation before the print job ccould start.



The first thing what I check is the printer is exists:



lpstat -p vasosamsung


If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.



If the answer is idle, or printing, the everything is fine, let's send the job.



BUT!



The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.



Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).



The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart, and get a stat:



printer vasosamsung is idle.  enabled since Thu 06 Apr 2017 03:34:26 PM CEST


It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:



string(40) "request id is vasosamsung-71 (1 file(s))"


and the job is on the web interface:



vasosamsung-71  Unknown     Withheld    1933k   1   held since


Thu Apr 6 15:59:43 2017



My question is: is there a way ti get the phisicaly printer status? Offline, printing etc... not from CUPS?



If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?



EDIT



Hehe, when I turned off my machine, the printer is idle also :)



I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.










share|improve this question

























  • Cant stop laughing. It is lying :-)

    – A Umar Mukthar
    Apr 6 '17 at 14:18











  • @AUmarMukthar First I thought that. I changed the name of question, but you were right.

    – vaso123
    Apr 6 '17 at 14:22











  • If the driver does not support it you won't be able to.

    – Rinzwind
    Apr 6 '17 at 14:38











  • How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

    – vaso123
    Apr 6 '17 at 14:42














0












0








0








We have some windows box on the network, and shared printers on them.



I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:



exec('lp -d vasosamsung file.pdf');


Cool. I worte a Printer class, what makes some validation before the print job ccould start.



The first thing what I check is the printer is exists:



lpstat -p vasosamsung


If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.



If the answer is idle, or printing, the everything is fine, let's send the job.



BUT!



The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.



Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).



The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart, and get a stat:



printer vasosamsung is idle.  enabled since Thu 06 Apr 2017 03:34:26 PM CEST


It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:



string(40) "request id is vasosamsung-71 (1 file(s))"


and the job is on the web interface:



vasosamsung-71  Unknown     Withheld    1933k   1   held since


Thu Apr 6 15:59:43 2017



My question is: is there a way ti get the phisicaly printer status? Offline, printing etc... not from CUPS?



If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?



EDIT



Hehe, when I turned off my machine, the printer is idle also :)



I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.










share|improve this question
















We have some windows box on the network, and shared printers on them.



I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:



exec('lp -d vasosamsung file.pdf');


Cool. I worte a Printer class, what makes some validation before the print job ccould start.



The first thing what I check is the printer is exists:



lpstat -p vasosamsung


If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.



If the answer is idle, or printing, the everything is fine, let's send the job.



BUT!



The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.



Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).



The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart, and get a stat:



printer vasosamsung is idle.  enabled since Thu 06 Apr 2017 03:34:26 PM CEST


It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:



string(40) "request id is vasosamsung-71 (1 file(s))"


and the job is on the web interface:



vasosamsung-71  Unknown     Withheld    1933k   1   held since


Thu Apr 6 15:59:43 2017



My question is: is there a way ti get the phisicaly printer status? Offline, printing etc... not from CUPS?



If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?



EDIT



Hehe, when I turned off my machine, the printer is idle also :)



I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.







printing cups-lpd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 6 '17 at 14:22







vaso123

















asked Apr 6 '17 at 14:02









vaso123vaso123

11511




11511













  • Cant stop laughing. It is lying :-)

    – A Umar Mukthar
    Apr 6 '17 at 14:18











  • @AUmarMukthar First I thought that. I changed the name of question, but you were right.

    – vaso123
    Apr 6 '17 at 14:22











  • If the driver does not support it you won't be able to.

    – Rinzwind
    Apr 6 '17 at 14:38











  • How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

    – vaso123
    Apr 6 '17 at 14:42



















  • Cant stop laughing. It is lying :-)

    – A Umar Mukthar
    Apr 6 '17 at 14:18











  • @AUmarMukthar First I thought that. I changed the name of question, but you were right.

    – vaso123
    Apr 6 '17 at 14:22











  • If the driver does not support it you won't be able to.

    – Rinzwind
    Apr 6 '17 at 14:38











  • How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

    – vaso123
    Apr 6 '17 at 14:42

















Cant stop laughing. It is lying :-)

– A Umar Mukthar
Apr 6 '17 at 14:18





Cant stop laughing. It is lying :-)

– A Umar Mukthar
Apr 6 '17 at 14:18













@AUmarMukthar First I thought that. I changed the name of question, but you were right.

– vaso123
Apr 6 '17 at 14:22





@AUmarMukthar First I thought that. I changed the name of question, but you were right.

– vaso123
Apr 6 '17 at 14:22













If the driver does not support it you won't be able to.

– Rinzwind
Apr 6 '17 at 14:38





If the driver does not support it you won't be able to.

– Rinzwind
Apr 6 '17 at 14:38













How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

– vaso123
Apr 6 '17 at 14:42





How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online.

– vaso123
Apr 6 '17 at 14:42










1 Answer
1






active

oldest

votes


















0














my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)



#define BUFFERLEN 1024
int isprtready( void )
{ char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat="lsusb > ",
enabled="Hewlett-Packard LaserJet 2420", filename="prtreadyXXXXXX";
int handle, len;

handle = mkstemp( filename );

strcpy( cmd, usbstat );
strcat( cmd, filename );
system( cmd );
len = read( handle, buffer, BUFFERLEN );
buffer[len] = '';
close( handle );
unlink( filename );

return ( strstr( buffer, enabled ) != (char*)NULL );
}


With the necessary includes

disadvantage: The explicit printer name is in my program.
(I have only one computer and one printer, no network and such things.)






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f900810%2fhow-to-check-is-printer-on-offline-with-cups%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)



    #define BUFFERLEN 1024
    int isprtready( void )
    { char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat="lsusb > ",
    enabled="Hewlett-Packard LaserJet 2420", filename="prtreadyXXXXXX";
    int handle, len;

    handle = mkstemp( filename );

    strcpy( cmd, usbstat );
    strcat( cmd, filename );
    system( cmd );
    len = read( handle, buffer, BUFFERLEN );
    buffer[len] = '';
    close( handle );
    unlink( filename );

    return ( strstr( buffer, enabled ) != (char*)NULL );
    }


    With the necessary includes

    disadvantage: The explicit printer name is in my program.
    (I have only one computer and one printer, no network and such things.)






    share|improve this answer






























      0














      my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)



      #define BUFFERLEN 1024
      int isprtready( void )
      { char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat="lsusb > ",
      enabled="Hewlett-Packard LaserJet 2420", filename="prtreadyXXXXXX";
      int handle, len;

      handle = mkstemp( filename );

      strcpy( cmd, usbstat );
      strcat( cmd, filename );
      system( cmd );
      len = read( handle, buffer, BUFFERLEN );
      buffer[len] = '';
      close( handle );
      unlink( filename );

      return ( strstr( buffer, enabled ) != (char*)NULL );
      }


      With the necessary includes

      disadvantage: The explicit printer name is in my program.
      (I have only one computer and one printer, no network and such things.)






      share|improve this answer




























        0












        0








        0







        my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)



        #define BUFFERLEN 1024
        int isprtready( void )
        { char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat="lsusb > ",
        enabled="Hewlett-Packard LaserJet 2420", filename="prtreadyXXXXXX";
        int handle, len;

        handle = mkstemp( filename );

        strcpy( cmd, usbstat );
        strcat( cmd, filename );
        system( cmd );
        len = read( handle, buffer, BUFFERLEN );
        buffer[len] = '';
        close( handle );
        unlink( filename );

        return ( strstr( buffer, enabled ) != (char*)NULL );
        }


        With the necessary includes

        disadvantage: The explicit printer name is in my program.
        (I have only one computer and one printer, no network and such things.)






        share|improve this answer















        my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)



        #define BUFFERLEN 1024
        int isprtready( void )
        { char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat="lsusb > ",
        enabled="Hewlett-Packard LaserJet 2420", filename="prtreadyXXXXXX";
        int handle, len;

        handle = mkstemp( filename );

        strcpy( cmd, usbstat );
        strcat( cmd, filename );
        system( cmd );
        len = read( handle, buffer, BUFFERLEN );
        buffer[len] = '';
        close( handle );
        unlink( filename );

        return ( strstr( buffer, enabled ) != (char*)NULL );
        }


        With the necessary includes

        disadvantage: The explicit printer name is in my program.
        (I have only one computer and one printer, no network and such things.)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 8 at 23:41









        karel

        60.8k13132155




        60.8k13132155










        answered Feb 8 at 22:56









        Hans R. VollmerHans R. Vollmer

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f900810%2fhow-to-check-is-printer-on-offline-with-cups%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?