LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script does not want to run, error (https://www.linuxquestions.org/questions/programming-9/script-does-not-want-to-run-error-48462/)

rhuser 03-05-2003 04:36 PM

Script does not want to run, error
 
Hi,

I am having problems opening this script on my machine. i have been getting help from a very helpful person on this list.

I have checked the shebang line, that perl exists, and perl -v gives proper output.

i try to run the script below as follow:

[root@cctv httpd]# cd cgi-bin
[root@cctv cgi-bin]# ls -la
total 28
drwxr-xr-x 2 me root 4096 Mar 5 21:49 .
drwxr-xr-x 5 me root 4096 Mar 3 01:50 ..
-rwxr-xr-x 1 me root 268 Mar 4 13:50 printenv
-rwxr-xr-x 1 me me 1792 Mar 5 15:20 renamer
-rwxr-xr-x 1 me me 1788 Mar 4 16:40 renamer.cgi
-rw------- 1 root root 1731 Mar 5 21:49 renamer.pl
-rwxr-xr-x 1 me root 757 Mar 3 01:50 test-cgi
[root@cctv cgi-bin]# renamer.pl &
[1] 10254
[root@cctv cgi-bin]# bash: renamer.pl: command not found

[1]+ Exit 127 renamer.pl
[root@cctv cgi-bin]#


[root@cctv cgi-bin]# ./renamer.pl &
[1] 10297
[root@cctv cgi-bin]# bash: ./renamer.pl: Permission denied

[1]+ Exit 126 ./renamer.pl
[root@cctv cgi-bin]#

Regards,

Mel

acid_kewpie 03-05-2003 04:38 PM

well it's not executable is it?

chmod +x renamer.pl

rhuser 03-05-2003 04:40 PM

Hi

thanks, sorry i did not mention this but i have done this, and still the same error.

acid_kewpie 03-05-2003 04:43 PM

well why have you posted saying
Code:

-rw------- 1 root root 1731 Mar 5 21:49 renamer.pl
surely that was the point of postnig that in the first place? lots of information is nice, but accurate information is much nicer.

so it runs if you just run "perl renamer.pl"?

rhuser 03-05-2003 04:48 PM

hi

sorry i am a newbie to this. i have done chmod a number of times in root but it still displays as above.

wapcaplet 03-05-2003 05:15 PM

If you've chmod +x it, and ls -l now shows:

-rwx--x--x yaddayadda renamer.pl

Or something like that, then:

perl renamer.pl

should work. If you're trying to run it by saying:

./renamer.pl

make sure the first line of renamer.pl is:

#!/usr/bin/perl

or whatever the path to perl is, otherwise your shell will not know how to run perl.

rhuser 03-05-2003 07:04 PM

thanks, for the help.
when i run the script i get an error with the script it self, could you help me out? tell me if you would, so i could show you the very basic script?

wapcaplet 03-05-2003 10:10 PM

Might help if you show it to us :)

rhuser 03-06-2003 06:49 AM

thank you.

#!/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 = <<EOUSAGE;
usage: $0 initial_name original_dir new_dir suffix
example: $0 image /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 ($min, $hour, $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";
}

acid_kewpie 03-06-2003 06:52 AM

so what's the error? come on man, we're not psychic!

rhuser 03-06-2003 07:43 AM

Re
 
sorry

well the script is running ok in the background. but could you pleae tell me how to start it it, and how to stop it.

The other question is that. the image name is supposed to change from image to date of image.

image.200372132.jpg

i would like it to display
20030703130230.jpg

2003 Year
07 Day
03 Month
1302 Time
30 Seconds

please how do i do this. also if i wanted to add a . between each variable, how to i do this?

e.g. 2003.07.03.13.02.30.jpg

Thanks for the help. i am a newbie to this.

Cheers,
Mel

wapcaplet 03-06-2003 07:53 AM

You said there was an error.... Is there an error message? If not, what is the script actually doing (if it's not renaming to date format as you wanted it to)? If the script is running in the background, how did it get started running if you didn't start it running?

I assume you solved the earlier problem with execution permissions?

Did you write this script, or did you get it from somewhere else? If you wrote it, perhaps it would be good to consult a perl reference.

rhuser 03-06-2003 08:02 AM

well, with all the advise on how to run the script, i think it is running as when i run the command

[root@cctv cgi-bin]# ps -aux | grep renamer
root 12772 0.0 0.4 3204 612 pts/1 S 13:54 0:00 grep renamer

it shows as the renamer is working.

I dont know which command set it running, but could someone please explain how to stop it, and run it again!!!

yeh thanks the execution permission problems are now solved.

The script i got from a mailing list, i did some basic changes to it. but not too sure on how to do the extra changes.

The script is to simply take an image named image.jpg from /home/httpd/htdocs and rename it with the date of the image, and move it to /home/me/images.

Thanks for all the help

wapcaplet 03-06-2003 10:15 AM

It looks like it is not running. When you do:

ps -ax | grep renamer

and get

root 12772 0.0 0.4 3204 612 pts/1 S 13:54 0:00 grep renamer

That's the process of _grep_ looking for "renamer." Grep found itself.

So what happens when you run:

./renamer.pl

or

perl renamer.pl

Anything at all? Any output? Does it rename any files, or does it just run and then exit?

rhuser 03-06-2003 03:27 PM

hi, thanks for the help

when i do this it just gives me an error:

[root@cctv cgi-bin]# ./renamer.pl&
> [2] 11033
> [1] Exit 127 renamer.pl
> [root@cctv cgi-bin]# usage: ./renamer.pl initial_name original_dir new_dir
> suffi
> x
> example: ./renamer.pl image /home/httpd/htdocs/ /home/me/images/ jpg
>
> [2]+ Exit 255 ./renamer.pl
> [root@cctv cgi-bin]#


All times are GMT -5. The time now is 03:48 AM.