Re: [opensuse] Re: how to set global environment variables in crontabs
As hinted in the last cited line:
the /etc/crontab is: ============================================== SHELL=/bin/bash ENV=/etc/profile.d/my-env.sh
If $SHELL is /bin/bash, $ENV is not read. Then $BASH_ENV is read.
Yes you are right. But I changed it to SHELL=/bin/sh and the same problem again. As you can see in my former posting, the variables are read (debug output from cron), but they are not set in the called cron (output from "set") Thanx Meike -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Meike Stone writes:
As hinted in the last cited line:
the /etc/crontab is: ============================================== SHELL=/bin/bash ENV=/etc/profile.d/my-env.sh
If $SHELL is /bin/bash, $ENV is not read. Then $BASH_ENV is read.
Yes you are right. But I changed it to SHELL=/bin/sh and the same problem again. As you can see in my former posting, the variables are read (debug output from cron), but they are not set in the called cron (output from "set")
You are right that ENV doesn't work. I don't know why, according to the docs it should. The following works at my workstation: /etc/crontab: ============================================================ SHELL=/bin/bash PATH=/usr/bin:/usr/sbin:/sbin:/bin MAILTO=root BASH_ENV=/tmp/setenv.sh # # check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly # * * * * * root /tmp/tstvar.pl ============================================================ /tmp/setenv.sh: ============================================================ export DEMO=demo ============================================================ /tmp/tstvar.pl: ============================================================ #!/usr/bin/perl open STDOUT, '>>/tmp/tstvar.out'; print "perl ENV DEMO: $ENV{DEMO}\n"; exit(0); ============================================================ created output file /tmp/tstvar.out: ============================================================ perl ENV DEMO: demo perl ENV DEMO: demo perl ENV DEMO: demo ============================================================ one line per minute. I use Perl to test that the env var is set for all cron jobs and not just for shell scripts. Joachim -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod, Roedermark, Germany Email: jschrod@acm.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Joachim Schrod said the following on 11/23/2012 10:49 AM:
I use Perl to test that the env var is set for all cron jobs and not just for shell scripts.
If you used the 'env' command you'd see a lot more and that _might_ give a clue. -- recursion (n): See recursion. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
You are right that ENV doesn't work. I don't know why, according to the docs it should. The following works at my workstation:
/etc/crontab: ============================================================ SHELL=/bin/bash PATH=/usr/bin:/usr/sbin:/sbin:/bin MAILTO=root BASH_ENV=/tmp/setenv.sh
I can confirm, that works now, the (first) problem is solved - thanks!
# # check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly # * * * * * root /tmp/tstvar.pl ============================================================
/tmp/setenv.sh: ============================================================ export DEMO=demo ============================================================
But now, I try to start the job from a crontab in /etc/cron.d, /etc/cron.daily , /etc/cron.hourly, /etc/cron.monthly, /etc/cron.weekly. That does not work. I don't get the Environment if i run 'env/set' it from there. These jobs there are invoked from /usr/lib/cron/run-crons, which is started from /etc/crontab. Thanks Meike -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 2012-11-23 19:12, Meike Stone wrote:
But now, I try to start the job from a crontab in /etc/cron.d, /etc/cron.daily , /etc/cron.hourly, /etc/cron.monthly, /etc/cron.weekly. That does not work. I don't get the Environment if i run 'env/set' it from there.
These jobs there are invoked from /usr/lib/cron/run-crons, which is started from /etc/crontab.
AFAIK you need to set the environment on each job separately. - -- Cheers / Saludos, Carlos E. R. (from 11.4 x86_64 "Celadon" (Minas Tirith)) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iF4EAREIAAYFAlCvz50ACgkQja8UbcUWM1xGPAD+M1enAmyZ/jPMg8aCoVYK5r4k TIffZZkw8Ouf+tm3cYoBAJWxsI8zsw2xTZdF/vhZ/kYRb5SGzpqCaRoZMv159sxG =dL0r -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
2012/11/23 Meike Stone <meike.stone@googlemail.com>:
You are right that ENV doesn't work. I don't know why, according to the docs it should. The following works at my workstation:
/etc/crontab: ============================================================ SHELL=/bin/bash PATH=/usr/bin:/usr/sbin:/sbin:/bin MAILTO=root BASH_ENV=/tmp/setenv.sh
I can confirm, that works now, the (first) problem is solved - thanks!
# # check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly # * * * * * root /tmp/tstvar.pl ============================================================
/tmp/setenv.sh: ============================================================ export DEMO=demo ============================================================
But now, I try to start the job from a crontab in cron.d, /etc/cron.daily , /etc/cron.hourly, /etc/cron.monthly, /etc/cron.weekly.
Sorry, I only mean /etc/cron.d. And this is called from the cron istself and not /usr/lib/cron/run-crons. My mistake. And therefore in each file must SHELL=/bin/bash BASH_ENV=/etc/profile.d/my-enc.sh included ... I understand, but I'm not so lucky about that. Thanks all for help! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Meike Stone writes:
2012/11/23 Meike Stone <meike.stone@googlemail.com>:
But now, I try to start the job from a crontab in cron.d, /etc/cron.daily , /etc/cron.hourly, /etc/cron.monthly, /etc/cron.weekly.
Sorry, I only mean /etc/cron.d. And this is called from the cron istself and not /usr/lib/cron/run-crons. My mistake. And therefore in each file must
SHELL=/bin/bash BASH_ENV=/etc/profile.d/my-enc.sh
included ...
I understand, but I'm not so lucky about that.
The problem is: We don't know enough about your use case. And, frankly, I don't want to know it exactly. We're entering the realm of consultancy, hand helding as FSF calls it, beyond helping fellow chaps on open source mailing lists. Usually, my company gets money for that... ;-) Your use case is not clearly articulated. Do you need the full range of env vars and other settings in your cron jobs? Or do you need just some few settings, e.g., to establish DB communication. (E.g., DB2 is famous for needing $DBINSTANCE or similar.) This leads to very different solution strategies. How many files in cron.d does one have? How often do they change? What change processes, what deployment automation (puppet, chef, et.al.) are in place at one's site? Maybe $BASH_ENV is a solution; maybe it's better to set env vars during service start as needed. This is very much situation dependent, and that's what a good Ops team is about. If you aren't charged to be Ops (and, for your sake, I hope you aren't), get in contact with them and talk about your problems. Hopefully they can put some process in this trial-and-error situation. Btw, any strategy you choose must take into account openSUSE's package management, too, for security reasons. Thus, a strategy for sysinitv might be different than a strategy for systemd. It's hard to tell in general terms if it's better to change crontab/cron.d files or systemd/sysinitv startup files to set env vars as needed, if one doesn't know which env vars, and for which services. Cheers, Joachim PS: I won't answer further for specific techical problems of the issue at hand, AFAICS, we're beyond that point. I'm open for discussion about general Ops or DevOps problems concerning openSUSE usage in commercial environments, as my company is concerned about that issuue. -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod, Roedermark, Germany Email: jschrod@acm.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (4)
-
Anton Aylward
-
Carlos E. R.
-
Joachim Schrod
-
Meike Stone