<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Splunking bash_history in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72894#M4598</link>
    <description>&lt;P&gt;lsolberg,&lt;BR /&gt;
If you don't mind adding the entire file as an event, you can use the file change monitor with fullEvent=true. This will work around the problem with the oldest entries being pushed out.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[fschange:/home/*/.bash_history]
index=bash
pollPeriod=600
fullEvent=true
sourcetype=bash_history
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another option would be to set HISTFILESIZE to be very very big, so the entries won't be pushed out. However, you eventually you'll hit that limit and your users would have to clear the history and start a new one, maybe saving the old history to a different location. If you don't like this option, you'll probably need to create a scripted input.&lt;/P&gt;

&lt;P&gt;As for the timestamps, the following settings in props.conf should help you, if you use &lt;CODE&gt;monitor&lt;/CODE&gt; rather than &lt;CODE&gt;fschange&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[bash_history]
BREAK_ONLY_BEFORE = #(?=\d+)
MAX_TIMESTAMP_LOOKAHEAD = 11
SHOULD_LINEMERGE = true
TIME_FORMAT = %s
TIME_PREFIX = #
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2012 21:18:44 GMT</pubDate>
    <dc:creator>echalex</dc:creator>
    <dc:date>2012-09-27T21:18:44Z</dc:date>
    <item>
      <title>Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72892#M4596</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I am trying to add the bash_history file but have runned into some problems.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The bash_history is timestamped (but not my very oldest entries)&lt;/LI&gt;
&lt;LI&gt;The timestamp is placed above the command, in the format #12345678 (unix-time)&lt;/LI&gt;
&lt;LI&gt;Old entries gets pushed out (after eg. 2000 entries).&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Example entries:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cd /root/backup
ls -la
nano /root/.bashrc
exit
#1348736649
ls
#1348736654
cd /etc
#1348737978
ps aux
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I make splunk index this nicely? And is there a way I can include both /root/.bash_history, and /home/.../.bash_history in the same stanza? Or even better, populate the files included from /etc/passwd (or a script).&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72892#M4596</guid>
      <dc:creator>lsolberg</dc:creator>
      <dc:date>2020-09-28T12:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72893#M4597</link>
      <description>&lt;P&gt;Here's a scriptlet if that helps (it'll also grab sh_history, csh_history, etc):&lt;BR /&gt;
It's not looking at /etc/passwd, but at the filesystem, which should work.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
for file in $(find /home|grep -E "\.\w*sh_history$"; find /root|grep -E "\.\w*sh_history$")&lt;BR /&gt;
do&lt;BR /&gt;
    echo "[monitor://$file]"&amp;gt;&amp;gt;inputs.conf&lt;BR /&gt;
    echo "sourcetype = shell_history"&amp;gt;&amp;gt;inputs.conf&lt;BR /&gt;
done&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Obviously I haven't answered your first question -- still thinking on that one.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:31:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72893#M4597</guid>
      <dc:creator>glitchcowboy</dc:creator>
      <dc:date>2020-09-28T12:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72894#M4598</link>
      <description>&lt;P&gt;lsolberg,&lt;BR /&gt;
If you don't mind adding the entire file as an event, you can use the file change monitor with fullEvent=true. This will work around the problem with the oldest entries being pushed out.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[fschange:/home/*/.bash_history]
index=bash
pollPeriod=600
fullEvent=true
sourcetype=bash_history
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another option would be to set HISTFILESIZE to be very very big, so the entries won't be pushed out. However, you eventually you'll hit that limit and your users would have to clear the history and start a new one, maybe saving the old history to a different location. If you don't like this option, you'll probably need to create a scripted input.&lt;/P&gt;

&lt;P&gt;As for the timestamps, the following settings in props.conf should help you, if you use &lt;CODE&gt;monitor&lt;/CODE&gt; rather than &lt;CODE&gt;fschange&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[bash_history]
BREAK_ONLY_BEFORE = #(?=\d+)
MAX_TIMESTAMP_LOOKAHEAD = 11
SHOULD_LINEMERGE = true
TIME_FORMAT = %s
TIME_PREFIX = #
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2012 21:18:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72894#M4598</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2012-09-27T21:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72895#M4599</link>
      <description>&lt;P&gt;Thanks! That worked just like advertised! I am using monitor, so I ended up using props.conf.&lt;BR /&gt;
As a bonus-question, is there an easy way to create a field for the 2nd line in the event? I want a field named command, but I am not that familiar on how regex works with multiline in Splunk. How can I use re.MULTILINE?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 09:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72895#M4599</guid>
      <dc:creator>lsolberg</dc:creator>
      <dc:date>2012-09-28T09:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72896#M4600</link>
      <description>&lt;P&gt;I thought it was an easier more elegant way.. We are using puppet, so I think I am ending up with a custom fact generated on the server every hour or so, and then puppet can generate the inputs.conf based on that.&lt;/P&gt;

&lt;P&gt;Thanks anyway &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 09:57:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72896#M4600</guid>
      <dc:creator>lsolberg</dc:creator>
      <dc:date>2012-09-28T09:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72897#M4601</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Using the field-extraction feature, you should be able to do what you want with a regex something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#\d+\n(?P&amp;lt;command&amp;gt;.*)$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 11:58:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72897#M4601</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2012-09-28T11:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72898#M4602</link>
      <description>&lt;P&gt;Thanks, I was able to create my own regex, but yours was more elegant.&lt;/P&gt;

&lt;P&gt;Added this to props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[bash_history]
EXTRACT-command = #\d+\n(?P&amp;lt;command&amp;gt;.*)$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2012 12:17:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72898#M4602</guid>
      <dc:creator>lsolberg</dc:creator>
      <dc:date>2012-09-28T12:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72899#M4603</link>
      <description>&lt;P&gt;No worries. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I did some further playing around with your idea and found that these settings in .bashrc are nice:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;HISTFILESIZE=1000000
HISTTIMEFORMAT='[%c] '
export HISTFILESIZE HISTTIMEFORMAT
export PROMPT_COMMAND='history -a'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;PROMPT_COMMAND&lt;/CODE&gt; setting will append to your history after each command, so it will end up in the index quicker. And makes it just a little bit harder for someone to cover up the tracks. Not impossible, mind you.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 12:26:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72899#M4603</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2012-09-28T12:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72900#M4604</link>
      <description>&lt;P&gt;What I did:&lt;BR /&gt;
Adding the following line:&lt;/P&gt;

&lt;P&gt;PROMPT_COMMAND="history -a;$PROMPT_COMMAND";&lt;/P&gt;

&lt;P&gt;to /etc/bashrc  This causes the .bash_history file to be written to immediately after a command finishes, which makes each command its own entry with its own time stamp.&lt;/P&gt;

&lt;P&gt;Entries like the ones below in splunk inputs.conf files will cause the .bash_history files to be indexed in splunk, thus keeping a record of commands run on linux servers.&lt;/P&gt;

&lt;P&gt;[monitor:///root/.bash_history]&lt;BR /&gt;
index = os&lt;BR /&gt;
sourcetype = cmdhistory&lt;BR /&gt;
source = root&lt;BR /&gt;
disabled = 0&lt;BR /&gt;
followTail = 1&lt;BR /&gt;
ignoreOlderThan = 1d&lt;/P&gt;

&lt;P&gt;For other accounts I want to monitory I add another stanza:&lt;/P&gt;

&lt;P&gt;[monitor:///home/oracle/.bash_history]&lt;BR /&gt;
index = os&lt;BR /&gt;
sourcetype = cmdhistory&lt;BR /&gt;
source = oracle&lt;BR /&gt;
disabled = 0&lt;BR /&gt;
followTail = 1&lt;BR /&gt;
ignoreOlderThan = 1d&lt;/P&gt;

&lt;P&gt;That works for me because I only have a small number of accounts that I want to monitor, but /etc/passwd is delimited, you could process it with a shell script that would add stanzas for each user.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:45:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72900#M4604</guid>
      <dc:creator>edonze</dc:creator>
      <dc:date>2020-09-28T12:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splunking bash_history</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72901#M4605</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I used the following modification in /etc/profile &lt;/P&gt;

&lt;P&gt;PROMPT_COMMAND='logger -i -p local5.info -t bash "$USER $(tty): $(history 1)"'&lt;BR /&gt;
or &lt;BR /&gt;
trap 'logger -i -p local5.info -t bash "$USER $(tty): $(fc -ln -1)"' DEBUG&lt;/P&gt;

&lt;P&gt;And rsyslog.d/shell.conf  to store it on a common file for all users :&lt;/P&gt;

&lt;P&gt;local5.*                                     -/var/log/shell.log&lt;/P&gt;

&lt;P&gt;My only issue is that I can't get sh or ksh commands with this.&lt;/P&gt;

&lt;P&gt;any suggestions ?&lt;/P&gt;

&lt;P&gt;Rgds&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2015 11:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunking-bash-history/m-p/72901#M4605</guid>
      <dc:creator>fulldanad</dc:creator>
      <dc:date>2015-08-27T11:42:37Z</dc:date>
    </item>
  </channel>
</rss>

