.bash_profile

.bash_profile
#~/.bash_profile
echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
PersonalServer=usmifmomlnxv001
Tmp="$(hostname -s)"
Host="$(echo "${Tmp}" | tr '[:upper:]' '[:lower:]')"
#
#
# Set our time-zone;
export TZ="America/New_York"
 
# Below doesn't change how the time is stored in the history
# file, only what it looks like with the history command.
HISTTIMEFORMAT="%F+%H:%M "
# Set defaults for the history file big and per machine.
HISTSIZE=11000
HISTDIR=${HOME}/.history
mkdir -p ${HISTDIR}
# Should exist, but just to be certain.
HISTFILE=${HISTDIR}/${Host}_history
 
function  HistOf() {
# This lets you get the history for a machine you aren't on at the
# moment, along with the date and time you ran the command.
if [ $# -eq 0 ]; then
        Q=${Host}
else
        Q=${1}
fi
if [ -e ~/.history/${Q}_history ] ; then
        while IFS= read -r Line
        do if [[ "${Line}" =~ ^#[0-9] ]]
                then date -d "${Line//#/@}" +"# %Y-%m-%d+%H:%M:%S"
                else echo "${Line}"
                fi
        done < ~/.history/${Q}_history
else echo "No history for ${Q}".
        fi
}
 
# And a thing to make and save logs, use like;
# <some program> | LOG
# Output goes to screen and log.
LOGFILE=${HISTDIR}/${Host}_log
LOG () {
        tee -a ${LOGFILE}
}
 
function KeyBackup() {
        sudo tar -czvf /tmp/$(hostname -s)-ssh.tgz /etc/ssh/ssh_host_*
        cp /tmp/$(hostname -s)-ssh.tgz ~/.HostKeys/
        sudo rm /tmp/$(hostname -s)-ssh.tgz
}
 
alias less='less -r'
# Above shows ansi colors in log files.
 
# If we're on the home machine, syncronize with OneDrive.
if [ "${Host}" == "${PersonalServer}" ] ; then
        # Run a sync if none has been done in the last day
   if [[ $(find /scratch/SRJ/.OneDrive -mtime +1 2>/dev/null) ]] ; then
           onedrive --sync
           touch /scratch/SRJ/.OneDrive
           echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
   fi
fi
 
# And, while we're here, how are the backups doing?
if [ "${Host}" == "${PersonalServer}" ] ; then
        Files=( /Backup/*/Summary )
        if [[ -e "${Files[0]}" ]]; then
                egrep --color=never '^/Backup' /Backup/*/Summary
                echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
        fi
fi
 
alias ls='ls --time-style="+%Y-%m-%d+%H:%M:%S"'
alias ll='ls -l'
alias l='ls -altr'
alias Rel='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2'
alias Diary='echo $(date +"%F+%R") : "${1}" >> ~/.history/$(hostname -s)_Diary'
alias Disks='lsblk -i -f -o type,size,fstype,name,mountpoint'
alias IP='ip a | grep -E "inet\ |inet6\ "'
alias Free='df -lBG --output=source,fstype,itotal,iused,ipcent,size,used,pcent,target -h | grep --color=never -E "^/|^Filesystem"'
alias Last='last -F | sed -n "1,/still running/{p}"'
[ -e /usr/bin/nmap ] && alias Nmap='nmap -Pn'
alias P='ping -qAc3'
alias Users='last -Fx | less'
alias Root='ssh -i ~/.ssh/id_dsa -l root'
alias RW='touch xyzzy-$(hostname -s) ; ls -l xyzzy-$(hostname -s) ; rm xyzzy-$(hostname -s)'
alias Count='last -Fw | cut -d " " -f1 | grep -vE "root|reboot|shutdown|runlevel|wtmp|^$" | sort | uniq -c | sort -rn'
alias Who='for User in $(last -Fw | grep -Ev "reboot|root|wtmp|runlevel|shutdown|^$" | cut -d " " -f1 | sort | uniq) ; do getent passwd ${User}; done | cut -d : -f 1,5,7'
alias Wttr='curl wttr.in/45103'
 
Rel=$(cat /etc/os-release | grep PRETTY | cut -d "=" -f 2)
 
# This line does a good job of identifying what we're running on
Platform=$(cat /sys/class/dmi/id/product_name)
if [ -z "${Platform}" ] ; then
        Platform=$(dmesg | grep -Ei 'DMI:.*' | cut -d ':' -f2)
fi
 
if [ -z "${Platform}" ] ; then
        Platform=$(hostnamectl | grep -i 'Hardware Model:' | cut -d: -f2-)
fi
 
if [ -d ~/bin ]
then
        PATH="~/bin:${PATH}"
fi
 
if [ -d ~/.local/bin ]
then
        PATH="~/.local/bin:${PATH}"
fi
 
echo ${Rel} on ${Platform}
echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
 
echo -n "Primary IP address is; "
ip route get 1.1.1.1 | awk '{print $7; exit}'
echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
 
echo 'Aliases available: ' $(alias | grep -E '^alias [A-Z]' | cut -c 7- | cut -d "=" -f1)
echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
 
# And, finally, if we're on the home machine, run ~/.sshrc
if [ "${Host}" == "${PersonalServer}" ]
then
        if [ -e ~/.sshrc ]
                then
                        . ~/.sshrc
        fi
fi
 
# If dealing with systemctl unit files, export vim as editor if it exists;
if [ -e /usr/bin/vim ]
        then
        export SYSTEMD_EDITOR=/usr/bin/vim
fi
 
# For a multi-line prompt that can easily be copied and pasted;
export PS1="\n## Type ↓ ↓ ↓, User \u in \w on \h ##\n"
 
# vim:ts=4:sw=4