Help really needed in this script: error: Prematue end of script header

Help really needed in this script: error: Prematue end of script header

am 05.03.2003 01:38:35 von mel awaisi

Hi,

I have with the help of one of the guys of this list got this script to take
an image from one directory and then rename it with the time and date of the
image and then store it onto a new directory.

I sotred the image in the cgi-bin, and then tried to run the file, i got
errors, when i went to the errorlog i got an error saying:
Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi

Regards,

Mel

#!/usr/bin/perl
use strict;
use warnings;

=head1 NAME

# renamer - renames files received by ftp, moving them to a new directory

=head1 SYNOPSIS

nohup ./renamer image /home/httpd/htdocs /home/me/images jpg &

=head1 DESCRIPTION

#The above instructs renamer to look for files called image.jpg in
/home/httpd/htdocs.
#It checks once per minute for such a file to appear. If it sees a
#readable file called /home/httpd/htdocs.jpg it moves it to
#/home/httpd/htdocs/image.200302251530.jpg where the number is a
#time stamp with year (four digits), month, day of the month, hour (in
#24 mode), and minute.

#Read the bugs section closely.

=head1 BUGS

#The original and new directories must be on the same file system.
#The program probably does not work on windows systems.
#The daemon behavior is weak.
#Not much testing has been done, so the script may have other problems.

=cut

my $usage = < usage: $0 initial_name original_dir new_dir suffix
example: $0 pic /home/httpd/htdocs /home/me/images jpg
EOUSAGE

my $check_file = shift or die $usage;
my $original_dir = shift or die $usage;
my $new_dir = shift or die $usage;
my $suffix = shift or die $usage;

exit if (fork());

while (1) {
process($check_file) if (-r "$original_dir/$check_file.$suffix");
sleep 60;
}

sub process {
my $file = shift;
my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];
$year += 1900;
$mon++;
my $stamp = "$year$mon$day$hour$min";

print
"renaming $original_dir/$file.$suffix to
$new_dir/$file.$stamp.$suffix\n";
rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
or warn "couldn't rename file $file to
$new_dir/$file.$stamp.$suffix\n";
}


____________________________________________________________ _____
It's fast, it's easy and it's free. Get MSN Messenger today!
http://messenger.msn.co.uk


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2068@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 02:46:51 von wiggins

mel awaisi wrote:
> Hi,
>
> I have with the help of one of the guys of this list got this script to
> take an image from one directory and then rename it with the time and
> date of the image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>

The script you have written is running as a pseudo-daemon, so you will
not want to run it as a cgi script. It should be running constantly, aka
run it from a terminal and background it. You need to separate the parts
of your app that will always be running, aka the script that grabs the
photos and moves them, from the parts that are web viewable, on demand,
more than one occurrence, etc. If your updating is only going to be
once a minute you might also consider just using cron rather than
sleeping for 60 seconds, but this is a design decision.



>
> exit if (fork());
>

This probably doesn't do what you want. Check out:

perldoc -q fork
perldoc -f fork
perldoc perlipc

fork returns the PID of the forked child upon success, and the PID will
always be positive so the above will always exit the program, which is
naturally not what you want.

> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>

Here do you want to pass only the filename sans-suffix? This is a
design decision. Later when you strip the subs into libraries you will
run into scoping issues. Essentially, ANYTHING used inside the sub
should either be created there or passed into it. For instance you might
be better off passing in the $suffix, $check_file, etc.

> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];

perldoc -f localtime
1 or more of your above variables will not be set correctly.

> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";

In warnings like the above you should always include $!, it is a special
variable that will tell you why what you were trying to do failed.

Looks like a good start... If you were in my class you would be well on
your way to an A, you included the strict/warnings and documentation
(two *very* good habits).

http://danconia.org


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2069@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 02:46:51 von wiggins

mel awaisi wrote:
> Hi,
>
> I have with the help of one of the guys of this list got this script to
> take an image from one directory and then rename it with the time and
> date of the image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>

The script you have written is running as a pseudo-daemon, so you will
not want to run it as a cgi script. It should be running constantly, aka
run it from a terminal and background it. You need to separate the parts
of your app that will always be running, aka the script that grabs the
photos and moves them, from the parts that are web viewable, on demand,
more than one occurrence, etc. If your updating is only going to be
once a minute you might also consider just using cron rather than
sleeping for 60 seconds, but this is a design decision.



>
> exit if (fork());
>

This probably doesn't do what you want. Check out:

perldoc -q fork
perldoc -f fork
perldoc perlipc

fork returns the PID of the forked child upon success, and the PID will
always be positive so the above will always exit the program, which is
naturally not what you want.

> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>

Here do you want to pass only the filename sans-suffix? This is a
design decision. Later when you strip the subs into libraries you will
run into scoping issues. Essentially, ANYTHING used inside the sub
should either be created there or passed into it. For instance you might
be better off passing in the $suffix, $check_file, etc.

> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];

perldoc -f localtime
1 or more of your above variables will not be set correctly.

> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";

In warnings like the above you should always include $!, it is a special
variable that will tell you why what you were trying to do failed.

Looks like a good start... If you were in my class you would be well on
your way to an A, you included the strict/warnings and documentation
(two *very* good habits).

http://danconia.org


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2069@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 02:46:51 von wiggins

mel awaisi wrote:
> Hi,
>
> I have with the help of one of the guys of this list got this script to
> take an image from one directory and then rename it with the time and
> date of the image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>

The script you have written is running as a pseudo-daemon, so you will
not want to run it as a cgi script. It should be running constantly, aka
run it from a terminal and background it. You need to separate the parts
of your app that will always be running, aka the script that grabs the
photos and moves them, from the parts that are web viewable, on demand,
more than one occurrence, etc. If your updating is only going to be
once a minute you might also consider just using cron rather than
sleeping for 60 seconds, but this is a design decision.



>
> exit if (fork());
>

This probably doesn't do what you want. Check out:

perldoc -q fork
perldoc -f fork
perldoc perlipc

fork returns the PID of the forked child upon success, and the PID will
always be positive so the above will always exit the program, which is
naturally not what you want.

> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>

Here do you want to pass only the filename sans-suffix? This is a
design decision. Later when you strip the subs into libraries you will
run into scoping issues. Essentially, ANYTHING used inside the sub
should either be created there or passed into it. For instance you might
be better off passing in the $suffix, $check_file, etc.

> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];

perldoc -f localtime
1 or more of your above variables will not be set correctly.

> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";

In warnings like the above you should always include $!, it is a special
variable that will tell you why what you were trying to do failed.

Looks like a good start... If you were in my class you would be well on
your way to an A, you included the strict/warnings and documentation
(two *very* good habits).

http://danconia.org


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2069@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 04:30:34 von Joshua Hoblitt

Mel,

I agree with the follow up posting on beginners that says this script should not be run as a CGI. However, just as an FYI, that particular error was being generated by Apache because you weren't outputting an HTTP content type.

On another issue I see that you cross posted this message across many unrelated lists. Including at least the datetime list. Please don't spam the Perl lists with irrelevant questions. beginners and beginners-cgi is the appropriate place to ask these kinds of question. The Perl community is very supportive and people in that community want to help you. Don't alienate those that you are asking for help.

Cheers,

-J

--

On Wed, 5 Mar 2003, mel awaisi wrote:

> Hi,
>
> I have with the help of one of the guys of this list got this script to take
> an image from one directory and then rename it with the time and date of the
> image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>
> Mel
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> =head1 NAME
>
> # renamer - renames files received by ftp, moving them to a new directory
>
> =head1 SYNOPSIS
>
> nohup ./renamer image /home/httpd/htdocs /home/me/images jpg &
>
> =head1 DESCRIPTION
>
> #The above instructs renamer to look for files called image.jpg in
> /home/httpd/htdocs.
> #It checks once per minute for such a file to appear. If it sees a
> #readable file called /home/httpd/htdocs.jpg it moves it to
> #/home/httpd/htdocs/image.200302251530.jpg where the number is a
> #time stamp with year (four digits), month, day of the month, hour (in
> #24 mode), and minute.
>
> #Read the bugs section closely.
>
> =head1 BUGS
>
> #The original and new directories must be on the same file system.
> #The program probably does not work on windows systems.
> #The daemon behavior is weak.
> #Not much testing has been done, so the script may have other problems.
>
> =cut
>
> my $usage = < > usage: $0 initial_name original_dir new_dir suffix
> example: $0 pic /home/httpd/htdocs /home/me/images jpg
> EOUSAGE
>
> my $check_file = shift or die $usage;
> my $original_dir = shift or die $usage;
> my $new_dir = shift or die $usage;
> my $suffix = shift or die $usage;
>
> exit if (fork());
>
> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>
> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];
> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";
> }
>
>
> ____________________________________________________________ _____
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://messenger.msn.co.uk
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2070@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 04:30:34 von Joshua Hoblitt

Mel,

I agree with the follow up posting on beginners that says this script should not be run as a CGI. However, just as an FYI, that particular error was being generated by Apache because you weren't outputting an HTTP content type.

On another issue I see that you cross posted this message across many unrelated lists. Including at least the datetime list. Please don't spam the Perl lists with irrelevant questions. beginners and beginners-cgi is the appropriate place to ask these kinds of question. The Perl community is very supportive and people in that community want to help you. Don't alienate those that you are asking for help.

Cheers,

-J

--

On Wed, 5 Mar 2003, mel awaisi wrote:

> Hi,
>
> I have with the help of one of the guys of this list got this script to take
> an image from one directory and then rename it with the time and date of the
> image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>
> Mel
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> =head1 NAME
>
> # renamer - renames files received by ftp, moving them to a new directory
>
> =head1 SYNOPSIS
>
> nohup ./renamer image /home/httpd/htdocs /home/me/images jpg &
>
> =head1 DESCRIPTION
>
> #The above instructs renamer to look for files called image.jpg in
> /home/httpd/htdocs.
> #It checks once per minute for such a file to appear. If it sees a
> #readable file called /home/httpd/htdocs.jpg it moves it to
> #/home/httpd/htdocs/image.200302251530.jpg where the number is a
> #time stamp with year (four digits), month, day of the month, hour (in
> #24 mode), and minute.
>
> #Read the bugs section closely.
>
> =head1 BUGS
>
> #The original and new directories must be on the same file system.
> #The program probably does not work on windows systems.
> #The daemon behavior is weak.
> #Not much testing has been done, so the script may have other problems.
>
> =cut
>
> my $usage = < > usage: $0 initial_name original_dir new_dir suffix
> example: $0 pic /home/httpd/htdocs /home/me/images jpg
> EOUSAGE
>
> my $check_file = shift or die $usage;
> my $original_dir = shift or die $usage;
> my $new_dir = shift or die $usage;
> my $suffix = shift or die $usage;
>
> exit if (fork());
>
> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>
> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];
> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";
> }
>
>
> ____________________________________________________________ _____
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://messenger.msn.co.uk
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2070@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.

Re: Help really needed in this script: error: Prematue end of scriptheader

am 05.03.2003 04:30:34 von Joshua Hoblitt

Mel,

I agree with the follow up posting on beginners that says this script should not be run as a CGI. However, just as an FYI, that particular error was being generated by Apache because you weren't outputting an HTTP content type.

On another issue I see that you cross posted this message across many unrelated lists. Including at least the datetime list. Please don't spam the Perl lists with irrelevant questions. beginners and beginners-cgi is the appropriate place to ask these kinds of question. The Perl community is very supportive and people in that community want to help you. Don't alienate those that you are asking for help.

Cheers,

-J

--

On Wed, 5 Mar 2003, mel awaisi wrote:

> Hi,
>
> I have with the help of one of the guys of this list got this script to take
> an image from one directory and then rename it with the time and date of the
> image and then store it onto a new directory.
>
> I sotred the image in the cgi-bin, and then tried to run the file, i got
> errors, when i went to the errorlog i got an error saying:
> Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi
>
> Regards,
>
> Mel
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> =head1 NAME
>
> # renamer - renames files received by ftp, moving them to a new directory
>
> =head1 SYNOPSIS
>
> nohup ./renamer image /home/httpd/htdocs /home/me/images jpg &
>
> =head1 DESCRIPTION
>
> #The above instructs renamer to look for files called image.jpg in
> /home/httpd/htdocs.
> #It checks once per minute for such a file to appear. If it sees a
> #readable file called /home/httpd/htdocs.jpg it moves it to
> #/home/httpd/htdocs/image.200302251530.jpg where the number is a
> #time stamp with year (four digits), month, day of the month, hour (in
> #24 mode), and minute.
>
> #Read the bugs section closely.
>
> =head1 BUGS
>
> #The original and new directories must be on the same file system.
> #The program probably does not work on windows systems.
> #The daemon behavior is weak.
> #Not much testing has been done, so the script may have other problems.
>
> =cut
>
> my $usage = < > usage: $0 initial_name original_dir new_dir suffix
> example: $0 pic /home/httpd/htdocs /home/me/images jpg
> EOUSAGE
>
> my $check_file = shift or die $usage;
> my $original_dir = shift or die $usage;
> my $new_dir = shift or die $usage;
> my $suffix = shift or die $usage;
>
> exit if (fork());
>
> while (1) {
> process($check_file) if (-r "$original_dir/$check_file.$suffix");
> sleep 60;
> }
>
> sub process {
> my $file = shift;
> my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];
> $year += 1900;
> $mon++;
> my $stamp = "$year$mon$day$hour$min";
>
> print
> "renaming $original_dir/$file.$suffix to
> $new_dir/$file.$stamp.$suffix\n";
> rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
> or warn "couldn't rename file $file to
> $new_dir/$file.$stamp.$suffix\n";
> }
>
>
> ____________________________________________________________ _____
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://messenger.msn.co.uk
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>


------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2070@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.