CRON job in Linux using a perl script....

I have a perl scrip that I am using to copy a file from one directory to another..... when I execute it :

$ perl perlscript.pl

It works fine...  

I want this script to run every day .... I do not know how to tell linux that it is a perl script when it executes otherwise it wont work....

Please advise.... I have webmin installed and cant figure it out in there either.
Thanks
 
Aschneider00Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

turn123Commented:
I've run a perl script buy giving the full path and it worked. e.g. /usr/home/turn/myscript
0
Karl Heinz KremerCommented:
You have to add this line as the first line of the script:

#!/usr/bin/perl
(or #!/usr/local/bin/perl, or wherever your perl executable is installed).

In addition to this, you have to make the file executable: chmod 755 perlscript.pl

And then, you have to add a crontab entry for this file.
0
Karl Heinz KremerCommented:
I'm back with my crontab instructions:
Run the following command:
crontab -e

This will bring up your editor with the crontab file loaded.
Add a line like this:
0 2 * * * /path/to/your/perl/script

This will run the program every night at 2:00am. The five fields are:

minute (0-59)
hour (0-23)
day of month (1-31)
month (1-12)
day of week (0-7)

This is also the order in which these fields are specified. If you want to always run the command, you use '*'.
So 0 2 * * * means: 0 minutes after 2 hours (2:00am) on every day, every monty and every day of the week.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Aschneider00Author Commented:
so all i have to do is make it executable and can run it as a CRON job?
so I dont have to put "perl" in front of the file  when I type

$ perl perlscript

???

 I will go try it
Thanks
 
0
Aschneider00Author Commented:
I changed the permissions and now I can execute it with

./perlscript.pl

but is there another way in  a gui that I can have it run.... for somereason I tried webmin and it is giving me this error...

cp: cannot create regular file `../html/bookmarks.html': No such file or directory

I am copying the bookmarks page from mozilla to the html directory for apache  " /var/www/html '
the script resides in "/ var/cgi-bin "

apache is the group that I have made the whole www owner of....

dont know what else.... I'd really like to get it setup in webmin,,,,,,

all i had was /var/www/cgi-bin/perlscript.pl in webmin and it should execute... ut it goves me that error.

Thanks in advance
0
Karl Heinz KremerCommented:
Can you post your script?

Does your program use relative paths (e.g. ../html/bookmarks.html like you quoted) for the destination? If so, change the directory first. If you don't call chdir, your current directory will be used by the script as the basis for all relative paths.
0
Aschneider00Author Commented:
#!/usr/bin/perl
use strict;
use CGI qw(:cgi);
#use CGI qw/:standard/;


my $file = "/home/USER/.mozilla/default/9c0cjyn4.slt/bookmarks.html";
my $destinationdir = "../html";

{
`cp $file $destinationdir/`;
}

this is whats in the file.... noithing that would mess with security... so here ya go
0
Aschneider00Author Commented:
Oh,
I tried putting in /var/www/html as the destination path and I dont think it worked... let me know what u think

0
Aschneider00Author Commented:
the folder structure for apache is as follows

                           www
                         /          \
                 cgi-bin     html      

I believe the script moves into the html folder correctly, because the script does work, its just about getting it to run automatically...
0
Karl Heinz KremerCommented:
OK, it's definitely the relative path for your destination path. What happens when you use /var/www/html ?

Why are you using a Perl script? The task is so simple that you can just write the copy command into a shell script:

#!/bin/sh

cp /home/USER/.mozilla/default/9c0cjyn4.slt/bookmarks.html /var/www/html

# end of script

Perl does not buy you anything in this case. Store this script e.g. as "copy.sh" (without the quotes) and make it executable (chmod 755 copy.sh). Then use this in your crontab file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aschneider00Author Commented:
I tried writing the shell script and I must not have had the syntx right.... Thanks!!

Reason I wanted to mess with perl was

1.  I just took a class with Unix and that was the current topic
2.  Usually isnt it good for autmoated things???

0
Karl Heinz KremerCommented:
Shure, in general Perl is much better than a shell script, but in this case, because the task is so simple (just one command), it's easier to just write the shell script.
ALso, in your Perl script, you don't have to use the CGI stuff: You are not writing a CGI script (for a web server).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.