ksh after perl script

E

E Arredondo

Hello, Please help me, I want to run a ksh script after a perl script on the
same cgi file, basically the perl is taking care of the uploading zip files
with photos from a website and then the korn shell uncompresses the received
files and moves them to their specific location and creates thumbnails, is
that possible ? Or maybe moving the ksh part of the script to a new file and
then making Perl execute it once it finishes with the first part . (i.e.
Perl execute "/script/processupload")

Here's how it gets run from a website : <FORM ACTION="/cgi-bin/upload.cgi"
METHOD="post" ENCTYPE="multipart/form-data">

Here's the actual script : upload.cgi

-------------------------------- start here -------------------

#!/usr/bin/perl -w
use CGI;
$upload_dir = "/www/docs/upload";
$query = new CGI;
$filename = $query->param("photo");
$claim = $query->param("claim");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("photo");
open (UPLOADFILE, ">$upload_dir/$filename")
or die "Can't write to directory '$upload_dir/$filename': $~\n";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
print $query->header ( );
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>
</BODY>
</HTML>

END_HTML


#!/bin/ksh <<<<<<<<<<<<<----------------------here's what's next
umask 0

photos=/www/docs/domain.com/jpg/claims/
cd /www/docs/upload

setcase -lr /www/docs/upload > /dev/null 2>&1

ls *zip | while read line
do
typeset -i CLAIM1=`echo $line | cut -f1 -d.`
typeset -i folder=`expr $CLAIM1 / 500`
typeset -i claim=`expr $CLAIM1`
if [ $claim -gt "100000" ]
then
if [ ! -d $photos$folder/$claim ]
then
mkdir -p $photos$folder/$claim
fi
if [ -d $photos$folder/$claim ]
then
cd $photos$folder/$claim
unzip -oq /www/docs/upload/$line
setcase -lr $photos$folder/$claim > /dev/null 2>&1

for lone in !(*tnail*)
do
if [ ! -f "tnail$lone" ]
then
echo $lone
/usr/local/bin/djpeg $lone | /usr/local/bin/pnmscale 0.2 |
/usr/local/bin/cjpeg > tnail$lone
fi
done
rm -rf /www/docs/upload/$line
fi
fi
done


------------------ cut here -------------------------------------


Thanks.
 
P

Paul Lalli

E said:
Hello, Please help me, I want to run a ksh script after a perl script on the
same cgi file, basically the perl is taking care of the uploading zip files
with photos from a website and then the korn shell uncompresses the received
files and moves them to their specific location and creates thumbnails, is
that possible ? Or maybe moving the ksh part of the script to a new file and
then making Perl execute it once it finishes with the first part . (i.e.
Perl execute "/script/processupload")

Put the shell program in a separate file, and then have the Perl
program execute that shell program, via the system() function.

system('/script/processupload');

perldoc -f system
for more information.

Paul Lalli
 
E

E Arredondo

Paul Lalli said:
Put the shell program in a separate file, and then have the Perl
program execute that shell program, via the system() function.

system('/script/processupload');

perldoc -f system
for more information.

Paul Lalli

Thanks so much! It's now doing what I wanted!

When I do the perldoc -f system, it gives me a bunch of file errors, Do I
have to be a super user ?

# perldoc -f system
sh: nroff: not found
=over 8

=item system LIST

=item system PROGRAM LIST

Does exactly the same thing as C<exec LIST>, except that a fork is
done first, and the parent process waits for the child process to
complete. Note that argument processing varies depending on the
number of arguments. If there is more than one argument in LIST,
or if LIST is an array with more than one value, starts the program
given by the first element of the list with arguments given by the
rest of the list. If there is only one scalar argument, the argument
is checked for shell metacharacters, and if there are any, the
entire argument is passed to the system's command shell for parsing
(this is C</bin/sh -c> on Unix platforms, but varies on other
platforms). If there are no shell metacharacters in the argument,
it is split into words and passed directly to C<execvp>, which is
more efficient.

Beginning with v5.6.0, Perl will attempt to flush all files opened for
output before any operation that may do a fork, but this may not be
supported on some platforms (see L<perlport>). To be safe, you may need


/tmp/gtIwTGqkQn Can't open /tmp/Fz75XtwO8G for reading: No such file or
direct at /usr/bin/pod2man line 60
 
P

Paul Lalli

E said:
Thanks so much! It's now doing what I wanted!

You're welcome.
When I do the perldoc -f system, it gives me a bunch of file errors, Do I
have to be a super user ?

# perldoc -f system
sh: nroff: not found
=over 8

<more POD snipped>

No. But you do have to get your local sysadmin to fix either your perl
installation or your nroff installation. In the meantime, consider
using the web interface to perldoc:
http://perldoc.perl.org
And just keep three translations in mind:
perldoc [something] ==> http://perldoc.perl.org/[something].html
perldoc -f [function] ==>
http://perldoc.perl.org/functions/[function].html
perldoc -q [phrase] ==> http://perldoc.perl.org/perlfaq.html (and
search for [phrase])

Paul Lalli
 
T

Tad McClellan

Paul Lalli said:
Put the shell program in a separate file, and then have the Perl
program execute that shell program, via the system() function.


Even better, since there is no more Perl needed after the ksh,
use the exec() function instead and save a whole process.
 
P

Paul Lalli

Tad said:
Even better, since there is no more Perl needed after the ksh,
use the exec() function instead and save a whole process.

Ahh, I was wondering if I should have said exec() there instead of
system(), but I couldn't think of any particular reason for one over
the other. Thanks for pointing one out to me.

Paul Lalli
 
E

E Arredondo

Tad McClellan said:
Even better, since there is no more Perl needed after the ksh,
use the exec() function instead and save a whole process.

Works too!, Thanks!
 
T

Tintin

Tad McClellan said:
Even better, since there is no more Perl needed after the ksh,
use the exec() function instead and save a whole process.

Or just convert the ksh script into Perl in the upload script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top