Add Donnagurai; Light Purple fix for OKiru
This commit is contained in:
95
Donnagurai
Executable file
95
Donnagurai
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
##Alias to show how long a process has been running.
|
||||
#+Thank Ron for this absolute banger.
|
||||
#source /root/.bash_profile > /dev/null 2>&1 #SLOW
|
||||
source "$SCRIPTS/Okiru"
|
||||
arg0=$(basename "$0")
|
||||
#Show help if arguments are misused
|
||||
usage()
|
||||
{
|
||||
exec 1>2 # Send standard output to standard error
|
||||
help
|
||||
exit 1
|
||||
}
|
||||
|
||||
flag_error()
|
||||
{
|
||||
echo -e "$arg0: $*." >&2
|
||||
help
|
||||
exit 1
|
||||
}
|
||||
|
||||
help()
|
||||
{
|
||||
echo "$arg0 - show how long a process has been running"
|
||||
echo " {-p|--process-id} # -- Process ID to check"
|
||||
echo " {-h|--help} -- Print this help message and exit"
|
||||
exit 0
|
||||
}
|
||||
#Pass arguments to the script
|
||||
declare -a PIDS=()
|
||||
flags()
|
||||
{
|
||||
if [[ $# == "0" ]]; then
|
||||
help
|
||||
exit 1
|
||||
elif [[ $# == "1" ]]; then
|
||||
if [[ $1 =~ ^[0-9].*$ ]]; then
|
||||
PIDS+=("$1")
|
||||
export PIDS
|
||||
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
help
|
||||
else
|
||||
flag_error "Invalid process ID: $1"
|
||||
fi
|
||||
else
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
(-p|--process-id)
|
||||
shift
|
||||
[ $# = 0 ] && flag_error "No process ID specified!"
|
||||
if [[ $1 =~ ^[0-9].*$ ]]; then
|
||||
PIDS+=("$1")
|
||||
export PIDS
|
||||
else
|
||||
flag_error "Invalid process ID: $1"
|
||||
fi
|
||||
shift;;
|
||||
(-h|--help)
|
||||
help;;
|
||||
(*) help;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
flags "$@"
|
||||
for pid in ${PIDS[@]}; do
|
||||
elapsed=$(ps -p $pid -o etime | grep -v "ELAPSED")
|
||||
cmd=$(ps -o command $pid | tail -1)
|
||||
if [[ -z $elapsed ]]; then
|
||||
printf "No data for PID ${RED}$pid${STOP}.\n"
|
||||
continue
|
||||
fi
|
||||
if [[ -n $(echo $elapsed | grep "-") ]]; then
|
||||
days=$(echo $elapsed | awk -F- '{print $1}')
|
||||
hours=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $1}')
|
||||
minutes=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $2}')
|
||||
seconds=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $2}')
|
||||
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$days${STOP} days, ${LIGHT_BLUE}$hours${STOP} hours, ${CYAN}$minutes${STOP} minutes and ${LIGHT_CYAN}$seconds${STOP} seconds.\n"
|
||||
elif [[ -z $(echo $elapsed | grep "-") ]]; then
|
||||
#If a process has been running for an hour or longer, output is 3 fields
|
||||
if [[ $(echo "$elapsed" | awk -F: '{print NF+1}') == 4 ]]; then
|
||||
hours=$(echo $elapsed | awk -F: '{print $1}')
|
||||
minutes=$(echo $elapsed | awk -F: '{print $2}')
|
||||
seconds=$(echo $elapsed | awk -F: '{print $2}')
|
||||
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$hours${STOP} hours, ${LIGHT_BLUE}$minutes${STOP} minutes and ${CYAN}$seconds${STOP} seconds.\n"
|
||||
#If running for less than an hour - only 2 fields
|
||||
elif [[ $(echo "$elapsed" | awk -F: '{print NF+1}') == 3 ]]; then
|
||||
minutes=$(echo $elapsed | awk -F: '{print $1}')
|
||||
seconds=$(echo $elapsed | awk -F: '{print $2}')
|
||||
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$minutes${STOP} minutes and ${LIGHT_BLUE}$seconds${STOP} seconds.\n"
|
||||
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user