Solved

crontab

Posted on 2004-08-01
19
517 Views
Last Modified: 2008-02-01
hi, can the crontab command be written twice on the same computer?
(1st crontab to execute FTP script, wanted to write a crontab to execute the perl
program right after FTP script had finish executing)
And whether perl program can run crontab?

thanks
0
Comment
Question by:TPoly
  • 8
  • 8
  • 2
  • +1
19 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 11690783
And whether perl program can run crontab?

you mean whether crontab can run perl programs ( i think)
and yes crontab can run any program ( provided necesary permission are there )

/abhijit/
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11690790
You can have more than 1 cron record, most of system have it anyway, for your situation
it is more reliable to use another script to run the FTP script and then the perl scrtpt.

#!/bin/ksh
#run the perlscript after ftpscript
/path-to/ftpscript
/path-to/perlscript
exit

then use cron to run it
0
 

Author Comment

by:TPoly
ID: 11690990
thanks... btw what type of script is that?
i mean i want to know the name for it :>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 11

Expert Comment

by:avizit
ID: 11690998
korn shell script
the first line gives you the hint

#!/bin/ksh
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691097
" btw what type of script is that?
i mean i want to know the name for it :>"

it is a korn shell  script, and you need to replace:
/path-to/ftpscript
/path-to/perlscript
with the REAL path and script Name for your FTP script and Perl script, then
save it to whatever name you like, eg. do-ftp, then put it into the crontab.

man crontab.

Or:
you can simplely add:
/path-to/perlscript

to your ftpscript, just before the "exit" statment. and use cron to run the FTP script.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11691154
BTW

By default cron jobs run in Bourne shell, not Korn shell.
The ftp-then-perl script uses nothing specific to Korn shell,
so you should write it as a Bourne shell script.  There should be
no other modifications except changing #!/bin/ksh to #!/bin/sh
on the first line.

0
 

Author Comment

by:TPoly
ID: 11691213
it do execute the FTP script
however it did not execute perl

both ways i've tried but it's only FTP that can worked

hope u can help me on this :)
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691221
You don't need to change #!/bin/ksh to #!/bin/sh
it will work, sine the first line of the script tell which shell syntax to be used for the script.

cron task can run almost any script (eg sh, ksh, bash, csh/tcsh, perl, and binary app
...) !
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691238
Do you have Perl install in your system?
 type in:
 which perl
or
find / -type f -name perl -print

To see if you have perl install, can you run the perl script in command line, and how
do you run it.

please post the first 2 lines of the perl script.

the first line should looks like:
#!/usr/bin/perl -w
or
#!/usr/local/bin/perl -w

it depands on where perl is installed



0
 

Author Comment

by:TPoly
ID: 11691240
nothing to do with #!/bin/ksh or #!/bin/sh
however it just cannot execute the perl
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691247
also make sure that your perl script is excutable, post the output of:
ls -al /path-to/perlscript
0
 

Author Comment

by:TPoly
ID: 11691252
this is the first 2 lines of the perl script:

#!/usr/bin/perl
use DBI;

i execute the perl by typing "perl mysqlperl.pl" in the command line
mysqlperl.pl = the perl filename
0
 

Author Comment

by:TPoly
ID: 11691258
-rwxr-xr-x    1 student  student       855 Aug  2 11:40 /home/student/mysqlperl.pl

this is the output of "ls -al /path-to/perlscript"
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691295
In command line, type in:
/home/student/mysqlperl.pl

see if if work?

if it works, you can use cron to run the script using your login env, the crontab
looks like:

30 23 * * * /bin/su - yourloginname -c "/path/to/your/script"

(run at 23:30pm)

also
type in:
 which perl
  post the output
0
 

Author Comment

by:TPoly
ID: 11691350

In command line, type in:
/home/student/mysqlperl.pl --> yes it works




30 23 * * * /bin/su - yourloginname -c "/path/to/your/script"
--> no it doesn't
0
 

Author Comment

by:TPoly
ID: 11691385
i'm using perl 5.6.1

OS - debian linux 3.0
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11691487
Do you need to set any ENV vars to run the perl script for the database?

eg: PATH, LD_LIBRARY_PATH etc,

then just add the ENV setting to the wrapper script, eg:
#!/bin/ksh
PATH=.....
LD_LIBRARY_PATH ...

export PATH LD_LIBRARY_PATH  ....
#run the perlscript after ftpscript
/path-to/ftpscript
/home/student/mysqlperl.pl
"exit

then modify the crontab:

30 23 * * * /bin/su - yourloginname -c "/path-to/aboutscript"


BTY,
>>   30 23 * * * /bin/su - yourloginname -c "/path/to/your/script"
>> --> no it doesn't

wil start the cron job at 23:30pm , how did you test it? it should work!
0
 

Author Comment

by:TPoly
ID: 11691665
i do not need to set any ENV vars as i'm able to run the perl
on its own for the db.

Still cannot run the perl after finishing the FTP transfer

ya the crontab work for the FTP but not the perl
0
 
LVL 38

Accepted Solution

by:
yuzh earned 300 total points
ID: 11691713
IF  you don't need to set any ENV vars as i'm able to run the perl THEN
    su - fred -c command
    use user fred's login env to run the command.
should work!
     
And put the following in the crontab:

30 23 * * * /bin/su - yourloginname -c "/path-to/yourscript  >/dev/null 2>&1 "

should work as well.

please REMEMBER to replace yourloginname with your Linux login name. and modify
the run time for the crontab.

man su
man crontab
to learn more details


0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I check if any IP address is available within a IP range I select ? 18 210
Linux daemon 11 355
inotifywait in linux 2 282
App holding yum lock unable to update my rpm package 1 54
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question