[crm] Here is my subject

The following is example output from my WordPress/Linux CLI Notes Engine Project.

# This is an example of my WordPress/Linux CLI Notes Engine output.
# Its reference can be found https://troys.io/wordpress-linux-cli-notes-engine
# Initial title was "Private: [crm] Here is my subject" because its default posts are private.  I've changed it to public within WordPress so you can see this example.
# Enjoy
exit
sudo postconf -e "home_mailbox = Maildir/"
sudo postconf -e "mailbox_command = "
sudo systemctl restart postfix
env
mail
exit
ls -al
cd /home/troy
ls -al
ls -al Maildir
mail troy
ls -al Maildir
tail -f /var/log/mail.log
dpkg-reconfigure postfix
systemctl restart postfix
tail -f /var/log/mail.log
cd /etc/postfix
ls -al
vi main.cf
vi /etc/aliases
systemctl restart postfix
exit
cat /var/log/commands.log | sed 's/ .$//'
cat /var/log/commands.log | sed 's/ .*$//'
cat /var/log/commands.log | sed 's/\.[^\.]*$//'
cat /var/log/commands.log
cat /var/log/commands.log | sed 's/\ [^\ ]*$//'
# Test this line ########
# Test this line ##### ##
# Test this line $%(^)%1!
cat /var/log/commands.log | sed 's/\ [^\ ]*$//'
cat /var/log/commands.log
vi /usr/bin/troysio
cp /usr/bin/troysio /usr/bin/troysio-redact
vi /usr/bin/troysio
troysio "testing last word chop"
vi /usr/bin/troysio
cat /var/log/commands.log | cut -d':' --complement -s -f1,2,3,4
vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing new cut"
cat /var/log/commands.log | cut -d':' --complement -s -f1,2,3,4
vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing new cut"
troysio uniq
vi /usr/bin/troysio
troysio uniq
troysio | uniq
vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing uniq"
vi /usr/bin/troysio
troysio "testing uniq"
cat -A /var/log/commands.log
cp /usr/bin/troysio /usr/bin/troysio-test
vi /usr/bin/troysio-test
troysio-test | cat -A
troysio-test | sub(/\r$/,"") | cat -A
troysio-test | cat -A
# Here is an example of a manual note on the command line.
# Hope you enjoy your note taking helper.
# Cheers.
troysio "here is my subject"
# WordPress post made with above command with title [crm] < host and "here is my subject" on the title of post.
# Joy

WordPress/Linux Bash CLI Notes Engine Facility

I created this process to improve my record keeping while working on a Linux bash shell. It allows for one to take notes while on the command line as well as publish to WordPress for tidy and organized record keeping.

Features:

  • Posts logs to WordPress from any Linux hosts.
  • Log all CLI commands to syslog globally.
  • Record literal notes to syslog.
  • Privately post logs to WordPress via CLI.
  • Posting of Subject from CLI to WP posts.
  • Auto insert [hostname] into WordPress post subject.
  • Auto remove undesired data from WP posts.
  • Auto insert [shortcode] into WordPress posts.

Roadmap:

  • Auto redact sensitive data on CLI WP post actions.
  • Record file changes to syslog (fork tripwire).
  • Post Categories to WordPress posts from CLI.
  • Post Tags to WordPress posts from CLI.

Requirements:

  • A self-hosted WordPress Installation.
  • The free Twenty Fifteen Theme.
  • FOSS Postie Plugin by Wayne Allen.
  • FOSS SyntaxHilighter Evolved by Alex Mills.
  • A pop3 mailbox (Postie to pull & DELETE emails).
  • Logger via the util-linux package.
  • Mailx via the mail-utils package.
  • Rsyslog via rsyslog package.
  • A bit of troysio microcode.

Steps:

  • Install WordPress.
  • Activate Twenty Fifteen Theme.
  • Download/Activate SyntaxHilighter Evolved in plugins.
  • Download/Activate Postie within plugins area.
  • Configure Postie to fetch and posts PRIVATELY text only.
  • Install mail-utils and util-linux packages on all Linux hosts.
  • Create your CLI logging syslog service.
  • Drop the following troysio microcode into e.g. /usr/local/bin/yourio and make it executable.
  • #!/bin/sh
    # Troy Perkins
    # https://troys.io
    # Note: Make sure to remove all "\"es from Shortcode lines before executing. I had to place them in order for this code to be published here due to surrounding bash shortcode in this post.
    
    #Host
    host=`hostname`;
    
    #Pop3 mailbox;
    mailb="your@email.com";
    
    #Content
    file='/var/log/commands.log';
    #file='/var/log/test.log';
    
    #Shortcode
    shrtstart='\[\bash]';
    shrtend='\[\/\bash]';
    
    { echo $shrtstart; cat $file | cut -d':' --complement -s -f1,2,3,4 | sed 's/\ [^\ ]*$//'; echo $shrtend; } | uniq | mailx -s "[$host] $1" $mailb
    

Usage:
To take manual notes type a # sign then your note then hit enter:

root@crm:# # Here is an example of a manual note on the command line.

To send notes to WordPress:

root@crm:# troysio "Here is my subject"

Example Output:

vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing new cut"
cat /var/log/commands.log | cut -d':' --complement -s -f1,2,3,4
vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing new cut"
troysio uniq
vi /usr/bin/troysio
troysio uniq
troysio | uniq
vi /usr/bin/troysio
vi /usr/bin/troysio-redact
troysio "testing uniq"
vi /usr/bin/troysio
troysio "testing uniq"
cat -A /var/log/commands.log
cp /usr/bin/troysio /usr/bin/troysio-test
vi /usr/bin/troysio-test
troysio-test | cat -A
troysio-test | sub(/\r$/,"") | cat -A
troysio-test | cat -A
# Here is an example of a manual note on the command line.
# Hope you enjoy your note taking helper.
# Cheers.
troysio "here is my subject"
# WordPress post made with above command with title [crm] < host and "here is my subject" on the title of post.
# Joy

To view the actual post, which I’ve changed from Private to Public just for you go here: https://troys.io/crm-here-is-my-subject/

Send CLI commands to syslog

Create a CLI command syslog service

echo "local6.*    /var/log/commands.log" >> /etc/rsyslog.d/bash.conf
systemctl restart rsyslog.service

Set global .bashrc shells to log

vi /etc/bash.bashrc

# log all bash shell sessions globally
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

To test new configuration:

  • Either log out and log back into your shell.
  • Or source bashrc with the command
    source ~/.bashrc
  • Or start a new shell with the command
    bash

Type a few commands… then

tail /var/log/commands.log