1

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

daveloyall
  • 2,140
  • 21
  • 23
AjayAware
  • 11
  • 1

1 Answers1

0

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.

norisknofun
  • 859
  • 1
  • 8
  • 24
  • Thanks norisknofun, I tried invoking the binary with bash script by sourcing .bash_profile then .bashrc and later both with environment variables but no luck yet. Steps followed were :- – AjayAware Feb 01 '16 at 12:16
  • Tried running binary via bash script by sourcing .bash_profile then .bashrc in it and later both with also env variables. Steps followed: >rc.local run bash script(a.sh) >a.sh source .bash_profile & .bashrc >a.sh exporting env variables >a.sh checking env variables via "env > file"(variables getting loaded) >a.sh running binary. Following these steps the binary is getting loaded to memory but not performing any task, even without using .bashrc and .bash_profile. but with env variables. Restarted same after some "SLEEP" in rc.local. Result -> binary loads to memory but not performing any task. – AjayAware Feb 01 '16 at 12:47
  • Tried playing with /etc/init/rc.conf and /etc/rc.d/init.d/functions, these files didnt helped. FYI the binary is getting loaded to memory but none of the commands in binary are getting executed. But the same binary if we run manually via cmd it works fine. – AjayAware Feb 01 '16 at 12:48
  • could you post some logs or anything you could observe ? – norisknofun Feb 01 '16 at 17:28
  • type=ANOM_PROMISCUOUS msg=audit(1454397278.351:4): dev=eth3 prom=256 old_prom=0 auid=4294967295 uid=0 gid=0 ses=4294967295 type=SYSCALL msg=audit(1454397278.351:4): arch=c000003e syscall=54 success=yes exit=0 a0=7 a1=107 a2=1 a3=7fffdcf84290 items=0 ppid=1868 pid=1871 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="binary" exe="/usr/binary" key=(null) type=LOGIN msg=audit(1454397413.434:14): pid=1885 uid=0 old auid=4294967295 new auid=0 old ses=4294967295 new ses=1 |||audit.log found related to issue. message & boot didn't had much||| – AjayAware Feb 02 '16 at 07:22
  • try to launch `ldd path/to/your/binary > ldd.results` from cron. Then check permissions to these pointed files and fill correctly `$LD_LIBRARY_PATH` with all folders – norisknofun Feb 02 '16 at 15:55
  • Already tried with that, Env variables set as ldd command output. After this only crontab worked properly (as mentioned in previous post). ldd binary redirect in file at boot, prior executing the binary is also coming out perfect. – AjayAware Feb 03 '16 at 09:20