
If you’re anything like me, lazy and slightly unorganized with multiple projects going on at the same time, you might just have more than one instance of Splunk running on your development server. I happen to have five, though I don’t run them all at the same time. You might point out that development does not require so many instances. Call me old-fashioned, but for all of Splunk’s flexibility I like to keep things as clean as I can, so I have;
- One instance of Splunk that doesn’t change much, this is my go-to backup demo server where I can show off finished/nearly finished apps and projects.
- A test instance where I work on all internal Splunk projects
- Another instance that is setup specifically for working with client data
- A ‘clean’ instance that I use to test alpha and beta rollouts of my apps
- A pre-release instance of the next version of Splunk for testing
One of the challenges that comes along with running so many instances on one box is the tedious task of setting and replacing the environment variables. I’m a lazy person… and typing in /opt/splunkinstance#1/bin/splunk restart (among other long strings and commands)… is not ideal for me. So I setup a little script to allow me to quickly change environments.
With this, all I need to do is type ‘. SplunkSettings.sh’ (the space between ‘.’ and the starting ‘S’ is important). It then gives me a list of instances, and I can easily swap my path and SPLUNK_HOME with a single keystroke (I’ve also set an APPS location as well). My paths could be echoed back to me, but I’ve simply left a confirmation (you can uncomment these lines in the code if you wish).
If you would like to do the same, just copy the script at the end of this post, save it as “whatever_you_want.sh”, make it executable and available to all users (chmod +x whatevery_you_namedit.sh), and move it to /usr/bin/. You will also want to edit the PATH variable that is included in the script to use your most recent one.
#! /bin/bash
########################################
# Choose your Splunk Environment
########################################
#Script to set multiple Splunk Instance Settings
printf "Choose a Splunk Environment:\n"
select d in /opt/splunk*/; do test -n "$d" && break; echo ">>>> Invalid Selection"; done
printf "you have chosen $d \n"
########################################
# Path is hard coded - consider altering
########################################
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games/
export PATH=$PATH:$d\bin
export SPLUNK_HOME=$d
export APPS=$d\etc/apps
#########################################
# Optional feedback and output
#########################################
#echo "PATH="$PATH
#echo "SPLUNK_HOME="$SPLUNK_HOME
#echo "APPS="$APPS
----------------------------------------------------
Thanks!
Dennis Bourg