Re: Shell Commands - Mailing list pgsql-general

From Antti Haapala
Subject Re: Shell Commands
Date
Msg-id Pine.GSO.4.44.0303061728490.25835-100000@paju.oulu.fi
Whole thread Raw
In response to Shell Commands  ("Carl Olivier" <carl@zero-one.co.za>)
Responses Re: Shell Commands  (Antti Haapala <antti.haapala@iki.fi>)
List pgsql-general
On Thu, 6 Mar 2003, Carl Olivier wrote:

> OK, so I am going to ask a bad question, but hey, here goes:
>
> In MSSql it is possible to run Shell commands from within Sql via any
> interface (suchg as JDBC) using mechanism MSSql provides....
>
> Is this possiible in POSTGRESql?  I know it is a security hole (through
> which many MS Servers are exploited), but was just wondering!
>
> Anyway, thanks in advance,

Could be easiest with plperlu (you need perl and plperl compiled
& installed, though):

# createlang plperlu

and after that

create or replace function do_readpipe(text) returns text as '
        my $command = shift;
        return `$command`;
'
language 'plperlu';

create or replace function do_shell(text) returns int as '
        my $command = shift;
        return system $command;
'
language 'plperlu';


select do_readpipe('cat /etc/passwd|grep root| cut -f 1-5 -d :');
   do_readpipe
-----------------
 root:x:0:0:root
(1 row)

ilmo=# select do_shell('echo "Hello World"|mailx antti.haapala@iki.fi');
 do_shell
----------
        0
(1 row)

Latter worked as expected.

--
Antti Haapala
+358 50 369 3535
ICQ: #177673735


pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: How to update rows from a cursor in PostgreSQL
Next
From: Bruce Momjian
Date:
Subject: Re: What filesystem?