script with "export" command in a crontab

2

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?

Bryan

Posted 2019-08-09T18:59:40.670

Reputation: 23

1What are you trying to do with it? – Cyrus – 2019-08-09T19:12:51.457

2

It probably does work. The script exports the variable to its environment, then it exits. A process can only change its own environment, or it can prepare environment for its child. Your script spawns no children; when it exits, the variable is no more. Where do you need this variable? For what process? For what user? Why do you need it updated every minute? (do you really?). Compare XY problem.

– Kamil Maciorowski – 2019-08-09T22:58:55.187

Try providing the full path to cat. (It's probably /bin/cat.) – Spiff – 2019-08-10T07:29:44.950

I need to store this variable to check it in an asterisk dialplan. Its the number of waiting calls in an OXE attendant switchboard i export it before from the OXE in a file on the asterisk server. ty – Bryan – 2019-08-11T15:26:09.773

Answers

1

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.

filbranden

Posted 2019-08-09T18:59:40.670

Reputation: 1 058

0

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

Bryan

Posted 2019-08-09T18:59:40.670

Reputation: 23

Ask a question on your real problem (asterisk, OXE attendant, switchboard) and explain exactly what you're trying to accomplish there, you might get good answers then. The answer is probably simple, but without enough details on what you're doing, it's really hard to give you any useful guidance... Good luck! – filbranden – 2019-08-12T15:17:06.953