LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-05-2003, 04:36 PM   #1
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Rep: Reputation: 15
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
 
Old 03-05-2003, 04:38 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965
well it's not executable is it?

chmod +x renamer.pl
 
Old 03-05-2003, 04:40 PM   #3
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
Hi

thanks, sorry i did not mention this but i have done this, and still the same error.
 
Old 03-05-2003, 04:43 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965
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"?
 
Old 03-05-2003, 04:48 PM   #5
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
hi

sorry i am a newbie to this. i have done chmod a number of times in root but it still displays as above.
 
Old 03-05-2003, 05:15 PM   #6
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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.
 
Old 03-05-2003, 07:04 PM   #7
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
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?
 
Old 03-05-2003, 10:10 PM   #8
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Might help if you show it to us
 
Old 03-06-2003, 06:49 AM   #9
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
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";
}
 
Old 03-06-2003, 06:52 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965
so what's the error? come on man, we're not psychic!
 
Old 03-06-2003, 07:43 AM   #11
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
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
 
Old 03-06-2003, 07:53 AM   #12
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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.
 
Old 03-06-2003, 08:02 AM   #13
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
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
 
Old 03-06-2003, 10:15 AM   #14
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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?
 
Old 03-06-2003, 03:27 PM   #15
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
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]#
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
run-parts gives error on bash script ChoKamir Programming 7 08-18-2014 06:31 AM
Error after editing /etc/rc/rc.local, Fedora freezes when tries to run the script simeandrews Fedora 1 06-24-2005 10:52 AM
run script error ust Linux - Software 7 09-09-2004 08:44 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
can't run a script script from icon in konqueror scottsteibel Linux - Software 1 08-02-2003 07:59 PM


All times are GMT -5. The time now is 12:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration