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
Next revision
Previous revision
bash_profile [2024/09/03 15:35] 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
 +Tmp="$(hostname -s)"
 +Host="$(echo "${Tmp}" | tr '[:upper:]' '[:lower:]')"
 # #
 # #
-# Set our time-zone, otherwise we get UTC and have to think;+# Set our time-zone;
 export TZ="America/New_York" export TZ="America/New_York"
  
-# Set defaults for the history stuff big and per machine. 
-# This is important because HOMEDIR is an nfs mount through  
-#  autofs across most  machines.  
 # Below doesn't change how the time is stored in the history # Below 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 "+HISTTIMEFORMAT="%F+%H:%M " 
 +# Set defaults for the history file big and per machine.
 HISTSIZE=11000 HISTSIZE=11000
 HISTDIR=${HOME}/.history HISTDIR=${HOME}/.history
-mkdir -p ${HISTDIR}  # Should exist, but just to be certain. +mkdir -p ${HISTDIR} 
-HISTFILE=${HISTDIR}/${HOSTNAME}_history+# 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; # And a thing to make and save logs, use like;
 # <some program> | LOG # <some program> | LOG
 # Output goes to screen and log. # Output goes to screen and log.
-LOGFILE=${HISTDIR}/${HOSTNAME}_log+LOGFILE=${HISTDIR}/${Host}_log
 LOG () { LOG () {
         tee -a ${LOGFILE}         tee -a ${LOGFILE}
 } }
  
-# Below shows ansi colors in log files.+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' alias less='less -r'
 +# 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 [ "${HOSTNAME}" == "PersonalBox" ] ; then +if [ "${Host}" == "${PersonalServer}" ] ; then 
-        onedrive --synchronize+        # 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, if we're on the home machinerun ~/.sshrc +# And, while we're herehow are the backups doing? 
-        if [ -e ~/.sshrc ] +if [ "${Host}" == "${PersonalServer}" ] ; then 
-        then . ~/.sshrc+        Files=( /Backup/*/Summary ) 
 +        if [[ -e "${Files[0]}" ]]; then 
 +                egrep --color=never '^/Backup' /Backup/*/Summary 
 +                echo '-=-=-=-=-=-=-=-=-=-=-=-=-=-'
         fi         fi
 fi fi
  
-# Get the aliases and functions +alias ls='ls --time-style="+%Y-%m-%d+%H:%M:%S"'
-if [ -f ~/.bashrc ]; then +
-        . ~/.bashrc +
-fi +
- +
-alias ls='ls --color=auto --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 l.='ls -d .*' +alias Rel='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2' 
-alias R='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2' +alias Diary='echo $(date +"%F+%R") : "${1}" >> ~/.history/$(hostname -s)_Diary' 
-alias D='lsblk -i -f -o size,fstype,name,mountpoint,uuid+alias Disks='lsblk -i -f -o type,size,fstype,name,mountpoint' 
-alias I='ip a | grep -E "inet|inet6"' +alias IP='ip a | grep -E "inet|inet6"' 
-alias F='df -lBM --output=source,iavail,avail,target -h'+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'
  
-# And, if you want the weather; +Rel=$(cat /etc/os-release | grep PRETTY | cut -d "=" -f 2)
-alias W='curl wttr.in'+
  
-cat /etc/*ease | 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
  
-# ~/bin is usually a link to a shared bin folder. 
 if [ -d ~/bin ] if [ -d ~/bin ]
 then then
Line 64: Line 111:
 fi fi
  
-# ~/.local/bin is per-machine 
 if [ -d ~/.local/bin ] if [ -d ~/.local/bin ]
 then then
Line 70: Line 116:
 fi fi
  
-# This line lists out the aliases with capital letters +echo ${Rel} on ${Platform} 
-echo 'Aliases available =' $(alias | grep -E '^alias [A-Z]' | cut -c 7- | cut -d "=" -f1)+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 # vim:ts=4:sw=4
 </code> </code>
bash_profile.1725377711.txt.gz · Last modified: by steve