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

Steve Cox -dig steve at dig.co.za
Mon May 12 14:48:18 CDT 2003


Okay will try that, no time tonite though. The backtic php thing never worked 
for me gave me an error, I tried rectifing it in php but never got it right. 
I can see where you are going and will give it a bash in the morning, can I 
call root stuff like this though, like /var/log/syslog has root permissions. 
Doesnt matter if you change it soon as the system writes to it it gets root 
perms again. Can your way pull from a root group user syslog file? 
Nonetheless, I'll experiment.

Regards
Steve Cox.

On Monday, 12 May 2003 21:30, Werner Moller wrote:
> 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