Crontab jobs don't see variables defined in /etc/profile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab jobs don't see variables defined in /etc/profile
# 1  
Old 10-27-2009
Crontab jobs don't see variables defined in /etc/profile

Is it true that Crontab jobs don't see variables defined in /etc/profile?
How to get around that?
# 2  
Old 10-27-2009
You could source /etc/profile in your job or script being called. The cron environment is different than an interactive shell and is much more sparse. Check out chapter 12 in Expert Shell Scripting (Apress).
# 3  
Old 10-27-2009
Using "#!/bin/bash -l" as shebang seems to bypass the problem as "-l"
makes bash act as if it had been invoked as a login shell. When bash is invoked as an login shell it first reads and executes commands from the file
/etc/profile, if that file exists.
But does using "#!/bin/bash -l" as shebang have any drawbacks?
# 4  
Old 10-27-2009
I suppose it depends on the cron job. Having the full login environment is probably convenient but is probably overkill since it likely has many pieces that are not necessary to your specific job. Worse case is that it would introduce unintended conflicts either initially or down the road.
# 5  
Old 10-27-2009
Quote:
Originally Posted by peterro
I suppose it depends on the cron job. Having the full login environment is probably convenient but is probably overkill since it likely has many pieces that are not necessary to your specific job. Worse case is that it would introduce unintended conflicts either initially or down the road.
I have to agree with that. I'd start with a "set > somefile", edit out everything you obviously don't need and bring that into the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How are environment variables defined in a Gnome terminal session?

Hello... and thanks in advance for any help anyone can offer me with my question! I'm hoping someone will have a little patience with me and walk me through this! I'm trying to understand a user login process on Centos 7 and I've gotten a bit confused trying to figure out when/how a Gnome... (4 Replies)
Discussion started by: bodisha
4 Replies

2. UNIX for Dummies Questions & Answers

Crontab jobs excuting

Hi i want to run the cronjob from 7 Am till 11.30Am for every 5 minutes from monday to friday. can anyone help? (15 Replies)
Discussion started by: satheesh_charle
15 Replies

3. Shell Programming and Scripting

Crontab jobs log

hi gurus, I have scheduled some script by using crontab. I would like to save all the logs in some particular directory whenever the jobs are running. please let me know how i need to code it to save the logs files. (2 Replies)
Discussion started by: arun888
2 Replies

4. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

5. UNIX for Dummies Questions & Answers

How to start jobs manually from Crontab

Hello - I have about 7 jobs listed in my crontab. They run automatically everyday. However I am wondering how to start them manually? My system is SunOS 5.10 Jobs are listed in this fashion: 41 00 * * 1-5 /system/volms/.vbc/startmeup 01 44 * * 0-6 /system/volms/.vbc/kill (space)... (7 Replies)
Discussion started by: DallasT
7 Replies

6. Shell Programming and Scripting

user-defined functions, "$@", $jobs and $ps wwaxu

Imagine a user-defined function. func() { /usr/pkg/bin/program long-string-of-switches-and-configs "$@" ;} I execute it once. Then background it. I execute another instance. Then bg it. func unique-user-input ^Z func unique-user-input ^Z First I view with ps ps wwaux ... (0 Replies)
Discussion started by: uiop44
0 Replies

7. UNIX for Dummies Questions & Answers

.profile - changes don't affect the login

I have modified the .profile in my profile and I don't see any effect. Why the changes don't have effect? I tried both on the account at a server where I have limited permissions as user and to my local pc (as user). Is it the .profile overridden by some other file? It looks weird because I... (8 Replies)
Discussion started by: myle
8 Replies

8. Shell Programming and Scripting

awk printf for user defined variables

I am working on a SunFire 480 - uname -a gives: SunOS bsmdb02 5.9 Generic_112233-08 sun4u sparc SUNW,Sun-Fire-480R I am tyring to sum up the total size of all the directories for each running database using awk: #!/usr/bin/ksh for Database in `ps -efl | grep "ora_pmon" | grep -v grep |... (1 Reply)
Discussion started by: jabberwocky
1 Replies

9. UNIX for Advanced & Expert Users

Crontab did not fire jobs

Hello, I have something weird that I need some solution and hope that you can help out there :). I have crontab entry and it is running everyday. Sometimes, the crontab will just hang/stale where my jobs will not be executed(of course, the user complaint, then only I know). I will need to do:... (4 Replies)
Discussion started by: hwh1
4 Replies

10. Programming

pre defined variables

Hi First I want to explain the scenerio : In my project I want to control the printing of some messages. Thats why I use #ifdef MESSAGE ------------print message-------------- #endif And when I compile the program with -DMESSAGE option, it shows all message and without -DMESSAGE option... (7 Replies)
Discussion started by: sumsin
7 Replies
Login or Register to Ask a Question