Solved

crontab

Posted on 2004-08-01
19
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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