User Tools

Site Tools


bash_profile

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
bash_profile [2026/07/27 19:14] stevebash_profile [2026/08/10 19:37] (current) steve
Line 2: Line 2:
 <code bash .bash_profile> <code bash .bash_profile>
 #~/.bash_profile #~/.bash_profile
 +echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
 PersonalServer=usmifmomlnxv001 PersonalServer=usmifmomlnxv001
-Host=$(hostname -s)+Tmp="$(hostname -s)
 +Host="$(echo "${Tmp}" | tr '[:upper:]' '[:lower:]')"
 # #
 # #
 # Set our time-zone; # Set our time-zone;
 export TZ="America/New_York" export TZ="America/New_York"
-  + 
-Set defaults for the history file big and per machine. +Below doesn't change how the time is stored in the history
-HISTTIMEFORMAT="%F+%H:%M " +
-# Above doesn't change how the time is stored in the history+
 # file, only what it looks like with the history command. # 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 HISTSIZE=11000
 HISTDIR=${HOME}/.history HISTDIR=${HOME}/.history
Line 18: Line 20:
 # Should exist, but just to be certain. # Should exist, but just to be certain.
 HISTFILE=${HISTDIR}/${Host}_history HISTFILE=${HISTDIR}/${Host}_history
-  +
-# 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  HistOf() { 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 if [ $# -eq 0 ]; then
-    Q=${Host}+        Q=${Host}
 else else
-    Q=${1}+        Q=${1}
 fi fi
 if [ -e ~/.history/${Q}_history ] ; then if [ -e ~/.history/${Q}_history ] ; then
-    while IFS= read -r Line +        while IFS= read -r Line 
-    do if [[ "${Line}" =~ ^#[0-9] ]] +        do if [[ "${Line}" =~ ^#[0-9] ]] 
-        then date -d "${Line//#/@}" +"# %Y-%m-%d+%H:%M:%S" +                then date -d "${Line//#/@}" +"# %Y-%m-%d+%H:%M:%S" 
-        else echo "${Line}" +                else echo "${Line}" 
-        fi +                fi 
-    done < ~/.history/${Q}_history+        done < ~/.history/${Q}_history
 else echo "No history for ${Q}". else echo "No history for ${Q}".
-    fi+        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() { function KeyBackup() {
         sudo tar -czvf /tmp/$(hostname -s)-ssh.tgz /etc/ssh/ssh_host_*         sudo tar -czvf /tmp/$(hostname -s)-ssh.tgz /etc/ssh/ssh_host_*
Line 48: Line 53:
         sudo rm /tmp/$(hostname -s)-ssh.tgz         sudo rm /tmp/$(hostname -s)-ssh.tgz
 } }
- +
 alias less='less -r' alias less='less -r'
 # Above shows ansi colors in log files. # Above shows ansi colors in log files.
- +
 # If we're on the home machine, syncronize with OneDrive. # If we're on the home machine, syncronize with OneDrive.
 if [ "${Host}" == "${PersonalServer}" ] ; then if [ "${Host}" == "${PersonalServer}" ] ; then
-        onedrive --sync+        # 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 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 ls='ls --time-style="+%Y-%m-%d+%H:%M:%S"'
 alias ll='ls -l' alias ll='ls -l'
 alias l='ls -altr' alias l='ls -altr'
 alias Rel='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2' alias Rel='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2'
-alias Diary='echo "${1}" >> ~/.history/$(hostname -s)_Diary_$(date +"%Y-%m-%d").txt'+alias Diary='echo $(date +"%F+%R") : "${1}" >> ~/.history/$(hostname -s)_Diary'
 alias Disks='lsblk -i -f -o type,size,fstype,name,mountpoint' alias Disks='lsblk -i -f -o type,size,fstype,name,mountpoint'
 alias IP='ip a | grep -E "inet\ |inet6\ "' 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 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}"' alias Last='last -F | sed -n "1,/still running/{p}"'
 +[ -e /usr/bin/nmap ] && alias Nmap='nmap -Pn'
 alias P='ping -qAc3' alias P='ping -qAc3'
 alias Users='last -Fx | less' alias Users='last -Fx | less'
-alias Root='ssh -i ~/.ssh/rtjmp -l root'+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 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 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' alias Wttr='curl wttr.in/45103'
-  + 
-cat /etc/*ease | grep PRETTY | cut -d "=" -f 2 +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 ] if [ -d ~/bin ]
 then then
         PATH="~/bin:${PATH}"         PATH="~/bin:${PATH}"
 fi fi
- +
 if [ -d ~/.local/bin ] if [ -d ~/.local/bin ]
 then then
         PATH="~/.local/bin:${PATH}"         PATH="~/.local/bin:${PATH}"
 fi fi
-  + 
-echo 'Aliases available =' $(alias | grep -E '^alias [A-Z]' | cut -c 7- | cut -d "=" -f1) +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 # And, finally, if we're on the home machine, run ~/.sshrc
 if [ "${Host}" == "${PersonalServer}" ] if [ "${Host}" == "${PersonalServer}" ]
Line 95: Line 134:
         fi         fi
 fi fi
- +
 # If dealing with systemctl unit files, export vim as editor if it exists; # If dealing with systemctl unit files, export vim as editor if it exists;
 if [ -e /usr/bin/vim ] if [ -e /usr/bin/vim ]
Line 101: Line 140:
         export SYSTEMD_EDITOR=/usr/bin/vim         export SYSTEMD_EDITOR=/usr/bin/vim
 fi fi
- +
 # For a multi-line prompt that can easily be copied and pasted; # For a multi-line prompt that can easily be copied and pasted;
 export PS1="\n## Type ↓ ↓ ↓, User \u in \w on \h ##\n" export PS1="\n## Type ↓ ↓ ↓, User \u in \w on \h ##\n"
-  + 
-# vim:ts=4:sw=4</code>+# vim:ts=4:sw=4 
 +</code>
bash_profile.txt · Last modified: by steve