[Za-pm] Using perl to call a bash script

Werner Moller mollerw at cmerce.com
Mon May 12 14:30:05 CDT 2003


Like so:

#!/usr/bin/perl

system("grep pppd /var/log/syslog > anewfile");

OR

$thecmd = `grep pppd /var/log/syslog > anewfile`; # Using the backtics ya
see

BUT

This is very nasty security practice, if you can do this your web server can
be wiped from anywhere by anyone with a bit of Unix sivvy(I can tell you
how...:?), rather do something like this:

#!/usr/bin/perl -w
# See above use strict with -w AND use tainted mode if possible, but let's
# not go into security here...

open FILE, "</var/log/syslog" or die "Cannot do that: $!\n";
while (<FILE>) {

	REST OF CODE GOES HERE
		ie. --> open NEWFILE, ">anewfile" or bla bla .... and so on

}
close FILE;

Let me know if you need more details though.

Hope this helps.

Cheers,
Werner Moller
wernerm at ifusion.co.za

PS: I did this on the fly so don't shoot me if the code don't run :)
-----Original Message-----
From: za-pm-admin at mail.pm.org [mailto:za-pm-admin at mail.pm.org]On Behalf
Of Steve Cox -dig
Sent: 12 May 2003 09:19 PM
To: za-pm at mail.pm.org
Subject: [Za-pm] Using perl to call a bash script


Two fold message,

Howdie all, just testing is this works,

Secondly, I use some php, but I am interested, can you call a bash script
from
perl (probably). If so, as a user/or from a webpage can I also call raw bash
comands like if the perl script is in the cgi-bin how could I include a raw
bash command (as root if possible) to pull the following to a file:

steve at steve]# grep pppd /var/log/syslog > anewfile

I cant get a root cronjob working and from a user I cant pull records from
the
/var/log/syslog

A simple example of typical output at www.dig.co.za go to "my home pc" then
"statistics" this at the moment is run manualy every so often. My script
works when I run it in bash manually, just as root its a no go.

Anyways, nice to have a perl list, and I know for fact it will help me
plenty.
I dig php but prefer perl for some stuff, so an integration of both is cool.

For what its worth, I run a small lan at home off a ADSl conection, 4
Mandrake
9.1 machines, one is a gateway samba server (P1 100mhz 32meg ram) and one
other P4 1.7 dual boots off seperate hdd to win98 for the time being. Others
plain Mandrake.

Oh b4 we have any flamewars - the best distro:
LINUX !

Regards
Steve Cox
_______________________________________________
Za-pm mailing list
Za-pm at mail.pm.org
http://mail.pm.org/mailman/listinfo/za-pm






More information about the Za-pm mailing list