Solved

crontab

Posted on 2004-08-01
19
511 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks... btw what type of script is that?
i mean i want to know the name for it :>
0
 
LVL 11

Expert Comment

by:avizit
Comment Utility
korn shell script
the first line gives you the hint

#!/bin/ksh
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
" 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

Expert Comment

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

Author Comment

by:TPoly
Comment Utility
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
Comment Utility
-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
Comment Utility
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
Comment Utility

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
Comment Utility
i'm using perl 5.6.1

OS - debian linux 3.0
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now