0

Almost a duplicate question of this one, however, the answer in that post does not solve the environmental issue with at command.

Problem description: I want to run my shell scripts with at command as a scheduled job. All my shell scripts run smoothly in a normal terminal in both Ubuntu 10.04 and 20.04 (3 different systems). I get all my results as expected. However, soon as I run my shell script with at, it does not run at all. Here are 3 cases to demonstrate that at works for simple operation and fails complex operation.

case 1

at works with simple script. Following is everything my shell script1.sh:

echo $(date) > ~/Desktop/time.txt

running at now + 1 minutes -f ~/script1.sh, it saves time into time.txt file. Great, it means that my at functions well.

case 2

at fails a simple script. Following is everything my shell script2.sh:

echo $(date) > ~/Desktop/time.txt
pycharm.sh

running at now + 1 minutes -f ~/script2.sh, it saves time into time.txt file, but the Pycharm was never opened. However, if I run sh script2.sh without using at, everything worked out perfectly, I get the time in time.txt file, and Pycharm opens normally. I think it simply means that at did not get all the variables in an existing terminal environment. Once I add export DISPLAY=:1 to script2.sh as

echo $(date) > ~/Desktop/time.txt
export DISPLAY=:1
pycharm.sh

then at now + 1 minutes -f ~/script2.sh would function correctly.

case 3

I need to run the following shell script with at as a scheduled job, script3.sh:

gjs -numberofsplits 50 -clusterplatform condor -condorscript condor.script main.mac  > ./output0.txt 2>&1
condor_submit main.submit  > ./output1.txt 2>&1

Please note that all these scripts runs normally in a terminal with sh script.sh, however, running the script with at now + 1 minutes -f ~/script3.sh, it throws an error saved in output0.txt file, it says

gjs: error while loading shared libraries: libG4global.so: cannot open shared object file: No such file or directory

I also tried to use the absolute path of gjs and condor_submit in script3.sh like

/home/albert/Products9/Gate/Gate-9.0-install/bin/gjs -numberofsplits 50 -clusterplatform condor -condorscript condor.script main.mac  > ./output0.txt 2>&1
/usr/bin/condor_submit  > ./output1.txt 2>&1

but it throws the same error.


solutions already tried

By far, I think the problem is well described. I think the cause of this problem is that at command does not have access to all the environment variables as in a normal terminal.

Here are the solutions I have tried posted here, hoping to get all environment variables exposed to at by adding

source $HOME/.profile

or

source $HOME/.bashrc

to the beginning of shell script. However, it does not solve or alleviate the problem at all.

asking for help

May I ask for help from you, the expert in this field, to solve this problem. As this problem may also trouble many other users. Thanks a lot.

1 Answer 1

1

One of the reasons is because the at command scheduler is not set to run on a GUI display by default. It should work if you add export DISPLAY=:0 to myscrpit.sh above the line pycharm.py. You can check the DISPLAY variable by typing echo $DISPLAY in a terminal window.

The other reason is the environment variables. The $PATH variable in cron jobs may not contain all the paths where the executables are. There may also be library files.

You can check the path for the executables by typing which <excutable> (e.g. which gjs). For the library directory the varible is $LD_LIBRARY_PATH and to see where the libraries it uses, it's ldd $(which gjs).

Then add export PATH=$PATH:<exepath> and export LD_LIBRARY_PATH=<libpath> to your at scripts.

7
  • Hi @Aenfa, thank you very much for your reply. I added export DISPLAY=:1 to myscrpit.sh above the line pycharm.sh, it still does not work. I don't see any difference. Meanwhile at does not work with other non-GUI programs either, like condor Mar 25, 2021 at 22:54
  • 1
    It could be that the path for pycharm.sh and condor are not in the $PATH variable when using at. You can check where they are by typing which pycharm.sh and which condor. Then use the full path in the script.
    – Aenfa
    Mar 25, 2021 at 23:00
  • You brought tons of sunshine into my day already. For pycharm.sh using the absolute path solved the problem. However, adding the absolute to gjs and condor_submit for condor has not solved the problem yet, but I think it is also very likely due to path issues. Is it possible to set it up so that at has access to normal environment variables? Mar 25, 2021 at 23:37
  • See what you get by adding > ~/Desktop/output.txt 2>&1 to the condor commands in the scripts then at now -f <script>. Let us know what error messages are in output.txt if any.
    – Aenfa
    Mar 25, 2021 at 23:40
  • Thank you so much for helping me debugging with great patience. Here is output.txt /home/user0/Products9/Gate/Gate-9.0-install/bin/gjs: error while loading shared libraries: libG4global.so: cannot open shared object file: No such file or directory, note that this error only happens when at is used, if I just run sh run_GATE.sh, everything works out fine. Mar 25, 2021 at 23:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .