<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perl socket script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283626#M715528</link>
    <description>It looks like part of your server side got chopped off but anyway, it's rather simple. Perl has the system function so once you capture the socket's input, you can build up as complicated a command as you wish.&lt;BR /&gt;&lt;BR /&gt;my $dir = '/etc';&lt;BR /&gt;my $cmd = sprintf("ls -l %s",$dir);&lt;BR /&gt;my $cc = system($cmd);&lt;BR /&gt;&lt;BR /&gt;This is just to illustrate what is possible. I would be rather careful in how you craft this because this could be a huge security hole. Normally it's not a good idea to build a general purpose remote command executor like this because it would be rather easy to do something rm -r * from /. The safer approach is to build a server that can only perform very limited actions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 21 May 2004 15:15:45 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2004-05-21T15:15:45Z</dc:date>
    <item>
      <title>perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283625#M715527</link>
      <description>In these two examples below I have:&lt;BR /&gt;socket.server.perl&lt;BR /&gt;socket.client.perl&lt;BR /&gt;&lt;BR /&gt;All it does is send a text string from &lt;BR /&gt;client to server and puts it in a file.&lt;BR /&gt;Can someone tell me how I can use this&lt;BR /&gt;example script to send and run a command on the&lt;BR /&gt;remote server instead of just sending the &lt;BR /&gt;string to a file on the remote server? See &lt;BR /&gt;code below. Is there is perl execute command &lt;BR /&gt;if recieved on the server side?&lt;BR /&gt;&lt;BR /&gt;socket.client.perl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;#===============================================&lt;BR /&gt;# Client -- using object interface&lt;BR /&gt;# Support Windows and UNIX&lt;BR /&gt;#===============================================&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;my $sock = new IO::Socket::INET (&lt;BR /&gt;    PeerAddr =&amp;gt; '128.166.11.13',&lt;BR /&gt;    PeerPort =&amp;gt; '9999',&lt;BR /&gt;    Proto =&amp;gt; 'tcp',&lt;BR /&gt;);&lt;BR /&gt;die "Could not create socket: $!\n" unless $sock;&lt;BR /&gt;print $sock "Hi there!\n";&lt;BR /&gt;$sock-&amp;gt;send("Hi again!\n");&lt;BR /&gt;&lt;BR /&gt;close($sock);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;socket.server.perl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;#===============================================&lt;BR /&gt;# Server -- using object interface&lt;BR /&gt;# Support Windows and UNIX&lt;BR /&gt;#===============================================&lt;BR /&gt;&lt;BR /&gt;#use Proc::Daemon;&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;#Proc::Daemon::Init();&lt;BR /&gt;&lt;BR /&gt;use POSIX qw(setsid);&lt;BR /&gt;&lt;BR /&gt;sub daemonize {&lt;BR /&gt;    die "Can't fork" unless defined (my $child = fork());&lt;BR /&gt;exit 0 if $child;&lt;BR /&gt;setsid();&lt;BR /&gt;open(STDIN, "open(STDOUT, "&amp;gt;/dev/null");&lt;BR /&gt;open(STDERR, "&amp;gt;&amp;amp;STDOUT");&lt;BR /&gt;chdir '/';&lt;BR /&gt;umask(0);&lt;BR /&gt;#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';&lt;BR /&gt;return $$;&lt;BR /&gt;                };&lt;BR /&gt;&lt;BR /&gt;&amp;amp;daemonize;&lt;BR /&gt;while() {&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 21 May 2004 14:59:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283625#M715527</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2004-05-21T14:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283626#M715528</link>
      <description>It looks like part of your server side got chopped off but anyway, it's rather simple. Perl has the system function so once you capture the socket's input, you can build up as complicated a command as you wish.&lt;BR /&gt;&lt;BR /&gt;my $dir = '/etc';&lt;BR /&gt;my $cmd = sprintf("ls -l %s",$dir);&lt;BR /&gt;my $cc = system($cmd);&lt;BR /&gt;&lt;BR /&gt;This is just to illustrate what is possible. I would be rather careful in how you craft this because this could be a huge security hole. Normally it's not a good idea to build a general purpose remote command executor like this because it would be rather easy to do something rm -r * from /. The safer approach is to build a server that can only perform very limited actions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 21 May 2004 15:15:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283626#M715528</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-05-21T15:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283627#M715529</link>
      <description>Sorry about that. Here is the script in it's&lt;BR /&gt;entirety.&lt;BR /&gt;It would be taylored to only execute one&lt;BR /&gt;command not an open perl script. Better&lt;BR /&gt;than having root .rhosts everywhere.&lt;BR /&gt;I think where it does the:&lt;BR /&gt;&lt;BR /&gt;print F $Line;&lt;BR /&gt;&lt;BR /&gt;at the bottom is where I could put some&lt;BR /&gt;kind of execute statement.&lt;BR /&gt;Take the string and run it not print it&lt;BR /&gt;to a file. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;socket.client.perl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;#===============================================&lt;BR /&gt;# Client -- using object interface&lt;BR /&gt;# Support Windows and UNIX&lt;BR /&gt;#===============================================&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;my $sock = new IO::Socket::INET (&lt;BR /&gt;PeerAddr =&amp;gt; '128.166.11.13',&lt;BR /&gt;PeerPort =&amp;gt; '9999',&lt;BR /&gt;Proto =&amp;gt; 'tcp',&lt;BR /&gt;);&lt;BR /&gt;die "Could not create socket: $!\n" unless $sock;&lt;BR /&gt;print $sock "Hi there!\n";&lt;BR /&gt;$sock-&amp;gt;send("Hi again!\n");&lt;BR /&gt;&lt;BR /&gt;close($sock);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;socket.server.perl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;#===============================================&lt;BR /&gt;# Server -- using object interface&lt;BR /&gt;# Support Windows and UNIX&lt;BR /&gt;#===============================================&lt;BR /&gt;&lt;BR /&gt;#use Proc::Daemon;&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;#Proc::Daemon::Init();&lt;BR /&gt;&lt;BR /&gt;use POSIX qw(setsid);&lt;BR /&gt;&lt;BR /&gt;sub daemonize {&lt;BR /&gt;die "Can't fork" unless defined (my $child = fork());&lt;BR /&gt;exit 0 if $child;&lt;BR /&gt;setsid();&lt;BR /&gt;open(STDIN, "open(STDOUT, "&amp;gt;/dev/null");&lt;BR /&gt;open(STDERR, "&amp;gt;&amp;amp;STDOUT");&lt;BR /&gt;chdir '/';&lt;BR /&gt;umask(0);&lt;BR /&gt;#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';&lt;BR /&gt;return $$;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;&amp;amp;daemonize;&lt;BR /&gt;while() {&lt;BR /&gt; my $new_sock = $sock-&amp;gt;accept();&lt;BR /&gt;&lt;BR /&gt;####################################&lt;BR /&gt;#   Put a message to file.          #&lt;BR /&gt;####################################&lt;BR /&gt;&lt;BR /&gt;while(defined($Line = &amp;lt;$new_sock&amp;gt;)) {&lt;BR /&gt; open (F,"+&amp;gt;&amp;gt;/lhome/root/testfile.txt");&lt;BR /&gt; print F $Line;&lt;BR /&gt; close F;&lt;BR /&gt;                                    };&lt;BR /&gt;    close($sock);&lt;BR /&gt;};  #End of while cycle</description>
      <pubDate>Fri, 21 May 2004 15:42:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283627#M715529</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2004-05-21T15:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283628#M715530</link>
      <description>In that case, $Line has your input so you can use it to execute whatever you like.&lt;BR /&gt;&lt;BR /&gt;Typically, your client should send a formatted request string of some type. I like to use &lt;TABS&gt; to separate the fields and then your server responds each time it sees a new line of input.&lt;BR /&gt;&lt;BR /&gt;&lt;/TABS&gt;</description>
      <pubDate>Fri, 21 May 2004 15:47:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283628#M715530</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-05-21T15:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283629#M715531</link>
      <description>I used your system($cmd) syntax and it works!&lt;BR /&gt;&lt;BR /&gt;Thanks Clay. This solves many problems here.&lt;BR /&gt;No more .rhosts to remote shutdown dbs for&lt;BR /&gt;backups. No more buying expensive agents&lt;BR /&gt;to do remote shutdowns etc...&lt;BR /&gt;&lt;BR /&gt;Now I have to have some kind of check on&lt;BR /&gt;the server side for valid commands.&lt;BR /&gt;&lt;BR /&gt;I don't understand your tab format??&lt;BR /&gt;</description>
      <pubDate>Fri, 21 May 2004 16:03:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283629#M715531</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2004-05-21T16:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283630#M715532</link>
      <description>All I am saying in that any client/server architecture, you must establish some sort of protocol.&lt;BR /&gt;&lt;BR /&gt;Let's suppose that your server does 4 things:&lt;BR /&gt;1) lists files in a dedicated directories&lt;BR /&gt;2) removes 1 file&lt;BR /&gt;3) add's a line to an existing file&lt;BR /&gt;4) kill the server&lt;BR /&gt;&lt;BR /&gt;Your create client requests that adhere to this, for example, you formant your protocol like this&lt;BR /&gt;request_code&lt;TAB&gt;string1&lt;TAB&gt;string2&lt;LF&gt;&lt;BR /&gt;&lt;BR /&gt;Now every line sent to the server expects these 3 arguments -- although some may simply be dummy args. Tabs are nice because unlike spaces or colons or commas they are not typically part of strings. Typically the request_code is something very easy to parse; e.g 1 - list; 2 - remove, 4 - kill,kill,kill&lt;BR /&gt;&lt;BR /&gt;If you wanrt to see some examples of this along with a little explanation, go to &lt;A href="http://www.sysadminmag.com" target="_blank"&gt;www.sysadminmag.com&lt;/A&gt; and look under the April '03 issue. I wrote an article that used Perl a Perl client/server pair to implement multi-host semaphores. Their web page also has a source code link where you will find the client and server pieces.&lt;BR /&gt;&lt;BR /&gt;&lt;/LF&gt;&lt;/TAB&gt;&lt;/TAB&gt;</description>
      <pubDate>Fri, 21 May 2004 18:14:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283630#M715532</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-05-21T18:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: perl socket script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283631#M715533</link>
      <description>Thanks Clay, I found your article. A bit&lt;BR /&gt;above me at this point.&lt;BR /&gt;&lt;BR /&gt;For now though. I just wanted something&lt;BR /&gt;simple to get around the root .rhosts problem. I was thinking as a security measure&lt;BR /&gt;of passing a code to the server.pl but don't&lt;BR /&gt;know the perl syntax at this time.&lt;BR /&gt;Could you show me the simple syntax for&lt;BR /&gt;passing two args.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;From client.pl send:&lt;BR /&gt;&lt;BR /&gt;1234  shutdown.sh&lt;BR /&gt;&lt;BR /&gt;On server.pl check code then run command:&lt;BR /&gt;&lt;BR /&gt;1234 shutdown.sh&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;On my client.perl I currently have:&lt;BR /&gt;&lt;BR /&gt;print $sock "shutdown.sh"&lt;BR /&gt;&lt;BR /&gt;On my server.perl I have:&lt;BR /&gt;&lt;BR /&gt;while(defined($Line = &amp;lt;$new_sock&amp;gt;)) {&lt;BR /&gt; system($Line);&lt;BR /&gt; close($sock);&lt;BR /&gt;};  #End &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I don't know how to separate the first arg&lt;BR /&gt;"1234" and test if it is a match before&lt;BR /&gt;running shutdown.sh. I assume this is what&lt;BR /&gt;you mean by tab delimits and I assume it&lt;BR /&gt;would be in your code I looked at on: &lt;BR /&gt;&lt;A href="http://www.samag.com/documents/s=7898/sam0304a/0304a.htm" target="_blank"&gt;http://www.samag.com/documents/s=7898/sam0304a/0304a.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 24 May 2004 08:56:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-socket-script/m-p/3283631#M715533</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2004-05-24T08:56:59Z</dc:date>
    </item>
  </channel>
</rss>

