lpr.sh

# source /path/to/lpr.sh

PRINTER="my_printer@localhost";

lpr() {
    FILE=$1;

    if [ -z $PRINTER ]; then
        echo "You have to set PRINTER."
        echo "Example: PRINTER='my_printer@localhost'";
        return 255;
    fi
    if [ -z $FILE ]; then
        echo "Usage: lpr <file>";
        return 254;
    fi
    if ! file $FILE | grep -i PostScript; then
        echo "File is not in postscript format";
        return 253;
    fi

    DST=(`echo $PRINTER|sed 's/@/ /'`);
    cat $FILE | ssh ${DST[1]} lpr -P ${DST[0]};
    echo "Job sent to '$PRINTER' ($?)";
    ssh ${DST[1]} lpq -P ${DST[0]};

    return 0;
}