I have sevaral jbos with bunch of export commands like export VARIABLE=value.
They work perfectly when I run manually but when I try to run from crontab it stops right at this export command.
But when I replace these export with these, crontab job works fine.
VARIABLE = value; export VARIABLE.
Is there a way to make crontab job work with the orginal way of exporting ( export VARIABLE=value). I have 100+ like this and don't want to send time modifying all these. :wall: :wall:
is a bash/ksh form. Many commands and systems like cron default you to sh, where you can't say that, but must say:
var_name='value' ; export var_name
If you are in csh, I think it is
setenv name value
or the like. Your crontab line can say
bash bash_script_name
or
ksh -c "commands . . . . "
but the slick thing is to make your script execvp() friendly: execuatable
chmod u+x path_to_script
and with the first line
#!/abs_path/to/interpreter one_optional_argument
so cron's sh execvp()'s it over to the right interpreter. You can make a sed script, for instance, with
#!/bin/sed -f
as the first line, since sed does not expect scripts by default, only under the -f option. For bash,
#!/usr/bin/bash
is all you need, as it expects script names. Don't forget or innovate, as execvp() is not imaginative. Verify the interpreter path with something like "which bash". As man execvp says, if you mess up, you get
@MKNENI
In Solaris the Shell used by cron is /usr/bin/sh which is one which does not allow the "export variable=value" syntax.
There are two solutions.
1) Prepend a shebang line for your normal shell to every script
2) Invoke your normal shell from the cron command line
e.g.
/usr/bin/ksh /pathtoscript/scriptname