#!/usr/bin/perl use strict; use warnings; use Getopt::Std; use LWP 5.64; sub usage {print <<_EOF_; NAME nopaste.pl SYNOPSIS nopaste.pl [-a ] [-p ] [-h] [description] DESCRIPTION Post any code/data received from stdin to the free pasting service at http://nopaste.php-q.net. The URL for the created entry will be displayed on stdout. OPTIONS -a do not use enviroment variable 'LOGNAME' for the poster's name field. -p activate nopaste's display parse errors feature. -h display usage information. EXAMPLES tail -n 20 /var/log/messages | nopaste.pl my syslog Take the last 20 lines of the syslog and post it with description "my syslog". nopaste.pl -a the nopaste script This script releasd into the public domain and is provided "as is". The author is not responsible for any failure or errors caused by the execution of this script. BUGS All bugs remaining strictly belong to the author, please send information on any found bug to tengri dot lethos at gmx dot net. _EOF_ } # variable declarations my $url = 'http://nopaste.php-q.net/add.php'; # nopaste submission url my $nick = 'nopaste from #debian.de'; # poster's name my $desc = 'none'; # description my $display_errors = '1'; # boolean for displaying parse errors my $code = ''; # pasted code my $MAX_FILE_SIZE ='61440'; # max file size for file upload my $pastefile = ''; # upload file name my %options = (); # hash used for command line parsing # parse command line die "aborted. - error parsing command line.\n" unless getopts('ahp', \%options); if (defined $options{h}) { usage(); exit(0); } $nick = $ENV{'LOGNAME'} unless defined $options{a}; $display_errors = 0 unless defined $options{p}; foreach (@ARGV) { $desc .= "$_ "; } # read data from stdin to code buffer if (-t STDIN && -t STDOUT) {die "aborted. - will not read from stdin interactivly.\n";} while () { $code .= $_; } die "aborted. - no data received from stdin.\n" unless length $code; # prepare and send form data my $req = LWP::UserAgent->new; my $res = $req->post ($url, [ 'nick' => $nick, 'desc' => $desc, 'display_errors' => $display_errors, 'code' => $code, 'MAX_FILE_SIZE' => $MAX_FILE_SIZE, 'pastefile' => $pastefile, ], 'content_type' => 'multipart/form-data', ); die "$url error: ", $res->status_line unless $res->is_success; die "weird content type at $url -- ", $res->content_type unless $res->content_type eq 'text/html'; # parse server response and display new url # the response substring we look for should contain something like: # The link to your code is if ($res->content =~ m{The link to your code is \\}) { print "http://nopaste.php-q.net/$1\n"; exit(0); } print "Ops! couldn't match url string in server response.\n"; print "full response data:\n"; print $res->content;