question on Net::LPR / Unix::Login

Discussion in 'Perl Misc' started by Huub, Jun 22, 2006.

  1. Huub

    Huub Guest

    Hi,

    Running FC5, I'm not sure if this is the right place to ask, but I'm
    trying Net::LPR to print to a remote printerserver. On CPAN I found nice
    examples, but I get permission errors on the printer when I run my code.
    Can I somehow 'su' to root from within Perl? Unix::Login only seems to
    be for validating an existing login.

    Thanks,

    Huub
    Huub, Jun 22, 2006
    #1
    1. Advertising

  2. Huub

    Ben Morrow Guest

    Quoth Huub <"v.niekerk at hccnet.nl">:
    >
    > Running FC5, I'm not sure if this is the right place to ask, but I'm
    > trying Net::LPR to print to a remote printerserver. On CPAN I found nice
    > examples, but I get permission errors on the printer when I run my code.
    > Can I somehow 'su' to root from within Perl? Unix::Login only seems to
    > be for validating an existing login.


    No, you can't. The only way is to run 'su' or 'sudo' with system.

    Why do you think this is necessary? You are probably better off invoking
    lpr(1) directly, and sendign the job as yourself.

    Ben

    --
    #!/bin/sh
    quine="echo 'eval \$quine' >> \$0; echo quined"
    eval $quine
    # []
    Ben Morrow, Jun 22, 2006
    #2
    1. Advertising

  3. Huub

    Huub Guest

    >
    > No, you can't. The only way is to run 'su' or 'sudo' with system.
    >


    Ok.

    > Why do you think this is necessary? You are probably better off invoking
    > lpr(1) directly, and sendign the job as yourself.
    >


    If I want to send the job as myself, access is denied. Unless I print by
    using the printmanager.
    The script should print data from a 900 record database on paper. So if
    I have to invoke lpr myself, I would have to print everything into a
    file, and then print that file. This sounds like doing the print job
    twice. Unless I can come up with another way to do it.
    Huub, Jun 22, 2006
    #3
  4. Huub

    Ben Morrow Guest

    [ please attribute quotations ]

    Quoth Huub <"v.niekerk at hccnet.nl">:
    > <>:
    > > Why do you think this is necessary? You are probably better off invoking
    > > lpr(1) directly, and sendign the job as yourself.

    >
    > If I want to send the job as myself, access is denied. Unless I print by
    > using the printmanager.


    ....you mean, by using the lpr program? That is because that is how you
    are supposed to print :).

    > The script should print data from a 900 record database on paper. So if
    > I have to invoke lpr myself, I would have to print everything into a
    > file, and then print that file. This sounds like doing the print job
    > twice. Unless I can come up with another way to do it.


    You can pipe the data into lpr.

    Ben

    --
    Musica Dei donum optimi, trahit homines, trahit deos. |
    Musica truces mollit animos, tristesque mentes erigit.|
    Musica vel ipsas arbores et horridas movet feras. |
    Ben Morrow, Jun 22, 2006
    #4
  5. Huub

    J. Gleixner Guest

    Huub wrote:
    >
    >> Why do you think this is necessary? You are probably better off invoking
    >> lpr(1) directly, and sendign the job as yourself.
    >>

    >
    > If I want to send the job as myself, access is denied. Unless I print by
    > using the printmanager.
    > The script should print data from a 900 record database on paper. So if
    > I have to invoke lpr myself, I would have to print everything into a
    > file, and then print that file. This sounds like doing the print job
    > twice. Unless I can come up with another way to do it.


    Show us how you're sending the information to lpr.
    J. Gleixner, Jun 22, 2006
    #5
  6. Huub

    Huub Guest

    > Show us how you're sending the information to lpr.

    use Net::LPR;

    my $lp = new Net::LPR (
    StrictRFCPorts => 1,
    RemoteServer => '10.0.0.2 DeskJet520',
    RemotePort => 515,
    PrintErrors => 0,
    RaiseErrors => 1,
    );

    my $data = " Contr. 2007\n
    Min. bijdrage 4,25 euro per
    jaar\n A.u.b. overmaken 15
    juli 2006\n\n\n\n\nLidnr. $record Lidnr. $record \n
    @straat @huisnr \n
    @postcode @plaats \n\n\n\n\n\n\n\n\n\n\n\n";

    $lp->connect() or die "Can't connect: ".$lp->error();

    my $jobkey = $lp->new_job();

    $lp->send_jobs('lp');
    $lp->job_mode_text($jobkey);
    $lp->job_send_control_file($jobkey);
    $lp->job_send_data($jobkey, $data, length($data));

    lp->disconnect() or die "Can't disconnect: ".$lp->error();


    I've taken most of this from CPAN, assuming it is working code. Thank
    you for helping out.
    Huub, Jun 22, 2006
    #6
  7. Huub

    Huub Guest

    >> RemoteServer => '10.0.0.2 DeskJet520',
    > ^^^^^^^^^^^
    > That doesn't look right. Try it with just the IP address or hostname,
    > but not both.


    That is the server-IP followed by printqueue.

    >
    > If the local system has a printcap definition for that printer, you
    > could just open a pipe to lpr and write the data there.
    >


    You mean like this?

    open my $lp, '|-', qw/lpr -PDeskjet520/ or die "can't fork lpr: $!";

    This complains about not having any data to print. lpr wants the name of
    a printjob, which I don't have.
    Huub, Jun 23, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Any LPR solution??

    , Sep 6, 2005, in forum: Java
    Replies:
    16
    Views:
    696
  2. Replies:
    12
    Views:
    1,635
    Dave Thompson
    Jan 10, 2005
  3. Replies:
    18
    Views:
    618
    Dave Thompson
    Jan 10, 2005
  4. loial

    lpr via subprocess in 2.4

    loial, Aug 4, 2010, in forum: Python
    Replies:
    3
    Views:
    322
    James Mills
    Aug 4, 2010
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    276
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page