Re: Shell Commands

From: Antti Haapala <antti(dot)haapala(at)iki(dot)fi>
To: Carl Olivier <carl(at)zero-one(dot)co(dot)za>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Shell Commands
Date: 2003-03-06 15:50:38
Message-ID: Pine.GSO.4.44.0303061728490.25835-100000@paju.oulu.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)haapala(at)iki(dot)fi');
do_shell
----------
0
(1 row)

Latter worked as expected.

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2003-03-06 15:56:22 Re: What filesystem?
Previous Message Bruce Momjian 2003-03-06 15:49:59 Re: How to update rows from a cursor in PostgreSQL