We have a RHEL6 server where IPtables, NetworkManager and sestatus are disabled. On that same server we have created a binary using C++ code.

That Binary when ran manually as root runs fine but when we try to run it on startup via rc.local and cronjob(of root, to run every 30mins) it doesn't gets loaded to server memory.

We tried using a shell script to initiate the binary on startup by placing binary path in script and adding the script to rc.local and cronjob. Still no Luck.

After playing around some environment variables i.e, we export them in script before running the binary. The cronjob issue got solved but the startup issue remains same. The variables used are "MANPATH, TERM, USER, LD_LIBRARY_PATH and PATH".

Please let me know if anyone has faced such issue and was able to solve it.

Thanks in advance

1

There are 1 answers

7
norisknofun On

Use a shell script to run tyour binary. At the beginning of the script, add after #!/bin/bash (depending of your favorite shell) :

source ~/.bash_profile

and/or

source ~/.bashrc

and/or

source ~/.profile

When cron launches a job, the used shell does not load anything. You must init the environment yourself.