crontab

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
TPolyAsked:
Who is Participating?
 
yuzhConnect With a Mentor Commented:
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
 
avizitCommented:
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
 
yuzhCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
TPolyAuthor Commented:
thanks... btw what type of script is that?
i mean i want to know the name for it :>
0
 
avizitCommented:
korn shell script
the first line gives you the hint

#!/bin/ksh
0
 
yuzhCommented:
" 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
 
brettmjohnsonCommented:
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
 
TPolyAuthor Commented:
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
 
yuzhCommented:
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
 
yuzhCommented:
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
 
TPolyAuthor Commented:
nothing to do with #!/bin/ksh or #!/bin/sh
however it just cannot execute the perl
0
 
yuzhCommented:
also make sure that your perl script is excutable, post the output of:
ls -al /path-to/perlscript
0
 
TPolyAuthor Commented:
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
 
TPolyAuthor Commented:
-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
 
yuzhCommented:
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
 
TPolyAuthor Commented:

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
 
TPolyAuthor Commented:
i'm using perl 5.6.1

OS - debian linux 3.0
0
 
yuzhCommented:
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
 
TPolyAuthor Commented:
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
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.

All Courses

From novice to tech pro — start learning today.