Currently, I have a script that loads my environment variables. And I'm sourcing it like this:
#!/bin/bash
set -x
# sourcing my env variables
. /etc/profile.d/company_env.sh > /dev/null 2>&1
clear_known_hosts(){
local known_hosts="${NAGIOS_HOME}/.ssh/known_hosts"
# clear
su - nagios -c "echo '' > ${known_hosts}"
}
But, removing the sourcing part, because I don't want to add it in every script that may create, my sudo
command can't find my environment variables, like NAGIOS_HOME
for example, which is empty.
Any suggestions ?