crontab doesn't get bash.bashrc variables [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
This question already has an answer here:
cron ignores variables defined in â.bashrcâ and â.bash_profileâ
5 answers
In Ubuntu 16.04 Bash 4.3.46(1) at the end of /etc/bash.bashrc I declared the following variable:
drt="/var/www/html"
I sourced the file (source /etc/bash.bashrc)
I executed crontab -e and added just for testing * * * * * touch /var/www/html/myFile.sh. This worked, while * * * * * touch $drt/myFile.sh didn't.
If a variable declared in bash.bashrc is global why it doesn't get processed by crontab?
Update1
I don't want to duplicate the stream drt="/var/www/html" into crontab (or cron.d) to avoid redundancy by principle.
Update2
I followed this session and it seems the answer marked as correct didn't solve my problem.
The second answer was somewhat unclear to me - why to put this conditional statement in (some?) bashrc file.
I also tried the third solution in relation to bash.bashrc (added SHELL=/bin/bash into the very start of crontab, saved the file and sourced bash.bashrc but had no change in a * * * * * touch ~/myfiile test.
I thus ask to reopen this question, or at least, clarify one the answers there.
cron variable bashrc
marked as duplicate by muru, Community⦠Jan 17 at 13:14
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
-2
down vote
favorite
This question already has an answer here:
cron ignores variables defined in â.bashrcâ and â.bash_profileâ
5 answers
In Ubuntu 16.04 Bash 4.3.46(1) at the end of /etc/bash.bashrc I declared the following variable:
drt="/var/www/html"
I sourced the file (source /etc/bash.bashrc)
I executed crontab -e and added just for testing * * * * * touch /var/www/html/myFile.sh. This worked, while * * * * * touch $drt/myFile.sh didn't.
If a variable declared in bash.bashrc is global why it doesn't get processed by crontab?
Update1
I don't want to duplicate the stream drt="/var/www/html" into crontab (or cron.d) to avoid redundancy by principle.
Update2
I followed this session and it seems the answer marked as correct didn't solve my problem.
The second answer was somewhat unclear to me - why to put this conditional statement in (some?) bashrc file.
I also tried the third solution in relation to bash.bashrc (added SHELL=/bin/bash into the very start of crontab, saved the file and sourced bash.bashrc but had no change in a * * * * * touch ~/myfiile test.
I thus ask to reopen this question, or at least, clarify one the answers there.
cron variable bashrc
marked as duplicate by muru, Community⦠Jan 17 at 13:14
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
This question already has an answer here:
cron ignores variables defined in â.bashrcâ and â.bash_profileâ
5 answers
In Ubuntu 16.04 Bash 4.3.46(1) at the end of /etc/bash.bashrc I declared the following variable:
drt="/var/www/html"
I sourced the file (source /etc/bash.bashrc)
I executed crontab -e and added just for testing * * * * * touch /var/www/html/myFile.sh. This worked, while * * * * * touch $drt/myFile.sh didn't.
If a variable declared in bash.bashrc is global why it doesn't get processed by crontab?
Update1
I don't want to duplicate the stream drt="/var/www/html" into crontab (or cron.d) to avoid redundancy by principle.
Update2
I followed this session and it seems the answer marked as correct didn't solve my problem.
The second answer was somewhat unclear to me - why to put this conditional statement in (some?) bashrc file.
I also tried the third solution in relation to bash.bashrc (added SHELL=/bin/bash into the very start of crontab, saved the file and sourced bash.bashrc but had no change in a * * * * * touch ~/myfiile test.
I thus ask to reopen this question, or at least, clarify one the answers there.
cron variable bashrc
This question already has an answer here:
cron ignores variables defined in â.bashrcâ and â.bash_profileâ
5 answers
In Ubuntu 16.04 Bash 4.3.46(1) at the end of /etc/bash.bashrc I declared the following variable:
drt="/var/www/html"
I sourced the file (source /etc/bash.bashrc)
I executed crontab -e and added just for testing * * * * * touch /var/www/html/myFile.sh. This worked, while * * * * * touch $drt/myFile.sh didn't.
If a variable declared in bash.bashrc is global why it doesn't get processed by crontab?
Update1
I don't want to duplicate the stream drt="/var/www/html" into crontab (or cron.d) to avoid redundancy by principle.
Update2
I followed this session and it seems the answer marked as correct didn't solve my problem.
The second answer was somewhat unclear to me - why to put this conditional statement in (some?) bashrc file.
I also tried the third solution in relation to bash.bashrc (added SHELL=/bin/bash into the very start of crontab, saved the file and sourced bash.bashrc but had no change in a * * * * * touch ~/myfiile test.
I thus ask to reopen this question, or at least, clarify one the answers there.
This question already has an answer here:
cron ignores variables defined in â.bashrcâ and â.bash_profileâ
5 answers
cron variable bashrc
edited Jan 16 at 19:29
asked Jan 15 at 14:38
Arcticooling
83123
83123
marked as duplicate by muru, Community⦠Jan 17 at 13:14
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Community⦠Jan 17 at 13:14
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The variables defined in *.bashrc are global only in the sense that they can be read out by programs running in the shell, and that they are handled specially by the shell. Whether a program reads these environmental variables and how they interpret them is completely dependent on the design and there is not regulation stating how a program should handle environment variables.
In short, the way cron interprets the crontab is decided by the program cron itself. It decides not to read the "global" environment variables and use its own syntax to define the "environment variables" instead. That's by design. If you can understand why we cannot just use $drt in a CMakeLists.txt, you should be able to understand why $drt in a crontab does not do what you expect it to do.
You can, of course, add the following line to your crontab if you wish.
drt="/var/www/html"
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The variables defined in *.bashrc are global only in the sense that they can be read out by programs running in the shell, and that they are handled specially by the shell. Whether a program reads these environmental variables and how they interpret them is completely dependent on the design and there is not regulation stating how a program should handle environment variables.
In short, the way cron interprets the crontab is decided by the program cron itself. It decides not to read the "global" environment variables and use its own syntax to define the "environment variables" instead. That's by design. If you can understand why we cannot just use $drt in a CMakeLists.txt, you should be able to understand why $drt in a crontab does not do what you expect it to do.
You can, of course, add the following line to your crontab if you wish.
drt="/var/www/html"
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
add a comment |Â
up vote
2
down vote
accepted
The variables defined in *.bashrc are global only in the sense that they can be read out by programs running in the shell, and that they are handled specially by the shell. Whether a program reads these environmental variables and how they interpret them is completely dependent on the design and there is not regulation stating how a program should handle environment variables.
In short, the way cron interprets the crontab is decided by the program cron itself. It decides not to read the "global" environment variables and use its own syntax to define the "environment variables" instead. That's by design. If you can understand why we cannot just use $drt in a CMakeLists.txt, you should be able to understand why $drt in a crontab does not do what you expect it to do.
You can, of course, add the following line to your crontab if you wish.
drt="/var/www/html"
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The variables defined in *.bashrc are global only in the sense that they can be read out by programs running in the shell, and that they are handled specially by the shell. Whether a program reads these environmental variables and how they interpret them is completely dependent on the design and there is not regulation stating how a program should handle environment variables.
In short, the way cron interprets the crontab is decided by the program cron itself. It decides not to read the "global" environment variables and use its own syntax to define the "environment variables" instead. That's by design. If you can understand why we cannot just use $drt in a CMakeLists.txt, you should be able to understand why $drt in a crontab does not do what you expect it to do.
You can, of course, add the following line to your crontab if you wish.
drt="/var/www/html"
The variables defined in *.bashrc are global only in the sense that they can be read out by programs running in the shell, and that they are handled specially by the shell. Whether a program reads these environmental variables and how they interpret them is completely dependent on the design and there is not regulation stating how a program should handle environment variables.
In short, the way cron interprets the crontab is decided by the program cron itself. It decides not to read the "global" environment variables and use its own syntax to define the "environment variables" instead. That's by design. If you can understand why we cannot just use $drt in a CMakeLists.txt, you should be able to understand why $drt in a crontab does not do what you expect it to do.
You can, of course, add the following line to your crontab if you wish.
drt="/var/www/html"
edited Jan 15 at 16:16
answered Jan 15 at 14:54
Weijun Zhou
1,434119
1,434119
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
add a comment |Â
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
1
1
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
This isn't entirely true. bashrc is only read by interactive shells, that's why cron doesn't use it.
â jordanm
Jan 15 at 15:03
add a comment |Â