Visit Our UNIX and Linux User Community


crontab job issues with export command


 
Thread Tools Search this Thread
Operating Systems Solaris crontab job issues with export command
# 1  
Old 02-22-2012
crontab job issues with export command

Hi all,

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. Smilie Smilie

Thanks in advance.
mkneni
# 2  
Old 02-22-2012
Well,
Code:
export var_name='value'

is a bash/ksh form. Many commands and systems like cron default you to sh, where you can't say that, but must say:
Code:
var_name='value' ; export var_name

If you are in csh, I think it is
Code:
setenv name value

or the like. Your crontab line can say
Code:
bash bash_script_name

or
Code:
ksh -c "commands . . . . "

but the slick thing is to make your script execvp() friendly: execuatable
Code:
chmod u+x path_to_script

and with the first line
Code:
#!/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
Code:
#!/bin/sed -f

as the first line, since sed does not expect scripts by default, only under the -f option. For bash,
Code:
#!/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
Code:
sh < your_not_sh_script_file

which can be disappointing in many ways! Smilie

Last edited by DGPickett; 02-22-2012 at 05:48 PM..
# 3  
Old 02-22-2012
If the first line of the cron job script is:
#!/bin/sh
export VARIABLE=value
will not work but
VARIABLE=value ; export VARIABLE
will.

If the first line is:
#!/bin/ksh
export VARIABLE=value
will work.
# 4  
Old 02-22-2012
Right, no need to revert to good old Bourne sh, execvp() treats all scripts alike, so use your favorite and enjoy portable skills.
# 5  
Old 02-23-2012
@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
# 6  
Old 02-27-2012
Thank you all. You are the best.

#!/bin/ksh woked great. This saved lot of trouble for me.

SmilieSmilieSmilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #949
Difficulty: Medium
In computer security, term virus and malware refer to the exact same thing.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crontab job is not working

hell all: i am trying to test a crontab job for snmpwalk but it is not working: here is crontab: */1 * * * * root /root/snmpwalk.sh for the script, it is very simple: #!/usr/local/bin/bash /usr/local/bin/snmpwalk -v 2c -c public 100.10.10.10 (6 Replies)
Discussion started by: ipfreak
6 Replies

2. SuSE

A crontab job not working

Hello, This is my first posting in Linux world. I have SLES 11. I've created a file 'packdisk-scandisk.txt' file under /var/opt/Teradata/bteqdba. The content of the file is, cat /var/opt/Teradata/bteqdba/packdisk-scandisk.txt output over /var/opt/Teradata/bteqdba/TAREAS_DBA.log... (2 Replies)
Discussion started by: JDBA
2 Replies

3. Shell Programming and Scripting

Crontab Job Syntax

I have a ksh script that does the following 1. Script executes and creates an output file from a sql query 2. That output file is an input file to the script 3. generates an html file to email to DBA receipients The following syntax works at the command line ... (1 Reply)
Discussion started by: JolietJake
1 Replies

4. Shell Programming and Scripting

Script that will be a cron job to export rrd files for cacti server

I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server. Here is the script: #!/bin/bash rm -rf /backup/cacti_xml/* cd /var/www/html/rra ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x Is there... (5 Replies)
Discussion started by: TheBigAmbulance
5 Replies

5. Shell Programming and Scripting

Schedule a job using Crontab

I would like to execute my script at 17.30 and 23.00 using crontab, could anybody help me out!! Thanks in Advance!! (1 Reply)
Discussion started by: jatanig
1 Replies

6. Solaris

cron / crontab issues - solaris 10

I am having some issues with my cronjobs not running in solaris 10. Cron is running: ~> ps -ef | grep cron root 202 1 0 Jul 18 ? 0:01 /usr/sbin/cron bender 1646 1562 0 01:57:49 syscon 0:00 grep cron crontab -l lists the cronjob and I *think* its in the... (8 Replies)
Discussion started by: ippy98
8 Replies

7. UNIX for Dummies Questions & Answers

crontab job not running

Hi all, down here part of the scheduled job in crontab (AIX Version 5) i have problem running jspPRE-ALL. i verrify permissions and privileges (the others job are working good) if i run the job in command line it work correctly # # Aggiornamento doni e continuity 00 02 * * 2-6... (5 Replies)
Discussion started by: ilpasta
5 Replies

8. Shell Programming and Scripting

problem running shell script (for oracle export) in crontab

Hello Gurus, I've been tasked with solving a problem at my new job and I'm stumped. We've got a script that dynamically builds an oracle export parameter files and then runs export from the shell. it runs fine when using the shell, but will NOT run (fails in one spot everytime) when entered... (1 Reply)
Discussion started by: jsheehan223
1 Replies

9. Shell Programming and Scripting

Help with a crontab job!!!

Hi, i need to schedule a script to run at 6.10AM everyday.I tried to do this way. #!bin/ksh 10 06 * * 0-6 sh /tmp/ss/script/daily_file_check.sh And at the command prompt I did >crontab -e cron.txt I'm not sure whether this is the right way. Can anyone please tell me how to... (4 Replies)
Discussion started by: kumarsaravana_s
4 Replies

10. UNIX for Dummies Questions & Answers

crontab job

Hi, I have cornjob was scheduled at 1:00 AM everyday. It has been running fine since last Saturday. But it didn't run since Saturday. Because of daytime saving time change it didn't ran? Please send me your thoughts. Thanks in adavance. Moe (3 Replies)
Discussion started by: Moe
3 Replies

Featured Tech Videos