Script with "Export" Command in a Crontab

Script with "Export" Command in a Crontab

I have this in cron tab: * * * * * /root/attente.sh and attente.sh : export attente=$(cat /root/switchboard.txt)

If I run export attente=$(cat /root/switchboard.txt) in a shell it works but not in cron job.

Any idea please?

4

2 Answers

The way environment variables work in Linux/Unix is per process and not for the whole system.

So, if you set an environment variable, that will affect only that process, where you set it.

If you export it, it means it will be preserved on processes spawned from that process. So, in a shell, or a shell script, that exported environment variable will be available in commands launched from that shell.

But environment variables you set in a specific process won't affect processes that were already running, or processes spawned from other processes (such as a shell, or a shell script) other than the one where the variable was exported.

So if you intended to update your shell's environment from that cron, unfortunately that doesn't work that way.

I finally found a workaround. I dont store the variable, I compare in asterisk with the FILE function, the first line of the file containing the value to other files with a different value (one file with a "1", another with "2" etc..) on the first line. But if someone has the solution for initial question, I'm still interested.

thanks

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.