1835533 Members
2983 Online
110078 Solutions
New Discussion

functions in cron jobs

 
SOLVED
Go to solution
Peter Gillis
Super Advisor

functions in cron jobs

Hi, A simple one for all you clever people...
Can a function be used in a script and executed via cron, and be expected to work properly?

op sys: ux11.00
system: D390

Thanks
maria.
5 REPLIES 5
Michael Tully
Honored Contributor
Solution

Re: functions in cron jobs

Hi Maria,

Basically any script or program can run from cron if the crontab entry and corresponding script has the appropriate permissions. Just about any program that you can run from the command line will run in cron.

Attached is an example script that has functions.

HTH
Michael
Anyone for a Mutiny ?
Peter Kloetgen
Esteemed Contributor

Re: functions in cron jobs

Hi Maria,

you can run every command and script with cron. But take care, that you make sure variables are known in your scripts and functions. So either export them before starting your scripts or define them into scripts or functions.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Allan Pincus
Frequent Advisor

Re: functions in cron jobs

Make sure when including these functions in your script that that the first line calls out the shell (or language) that references the functions, like:

#!/usr/bin/shell_name

But you probably knew that ;-)

- Allan
harry d brown jr
Honored Contributor

Re: functions in cron jobs


Maria,

When dealing with cron's you must remember that the ENVIRONMENT variables are very limited.

Now as for a cron job, say a SHELL SCRIPT with functions, yes that shell script will operate correctly, BUT REMEMBER the rule above!

live free or die
harry
Live Free or Die
Peter Gillis
Super Advisor

Re: functions in cron jobs

Thanks to all for your input.
Maria.