-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_func
More file actions
144 lines (108 loc) · 3.33 KB
/
bash_func
File metadata and controls
144 lines (108 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# activ() {
# conda activate "$1"; conda env list
# }
cmdfreq() {
num=${1:-10}
history | cut -c 8- | sort | uniq -c | sort -rn | head -${num}
}
# deact() {
# conda deactivate; PS1=$(echo "$PS1" | perl -pe 's/^\(base\)\s*//' ); conda env list
# }
clean-prompt() {
# PS1=$(echo "$PS1" | perl -pe 's/^\(\/Users\/laufers\/anaconda3\)\s*//')
# PS1=$(echo "$PS1" | perl -pe 's/^\(base\)\s*//')
PS1=$(echo "$PS1" | perl -pe 's/^\(${1}\)\s*//')
}
ffile() { find . -type f -name "*$1*" -print ; }
gpw() { grep -i "$1" /etc/passwd ; }
laston() { last| grep -i "$1" | head -15; }
llg() { ls -la |grep -i "$1" | grep -v grep ; }
nuke() { set j = `ps x | grep "$1" | grep -v grep`;\ kill -9 $j[1]; echo "kill -9 $j[1]" ; }
pman() { man -t "$1" | open -f -a Preview ; }
psg() { ps aux | grep -i "$1" | grep -v grep ; }
pwg() { grep -i "$1" /etc/passwd ; }
rmfiles() { find . -name "*$1*" -print -exec \rm {} \; ; }
rmf() { find . -name "*$1*" -print -exec \rm {} \; ; }
rmtest() { find . -name "*$1*" -exec \echo 'The file' {} 'will be deleted' \; ; }
seek() { find . -name $1 -print ; }
slay() { set j = `ps1 guw | grep "$@" | grep $USER | grep -v grep` ; echo $j ; k9 $j[2] ; }
whentime() {
# if [ -z "$1" ]; then
# time_str=0
# else
# time_str="$1"
# fi
python -c "
import datetime
import sys
def calculate_time(delta_hours):
current_time = datetime.datetime.now()
delta = datetime.timedelta(hours=delta_hours)
new_time = current_time + delta
return new_time.strftime('%a %b %d %H:%M:%S %Z %Y')
try:
delta_hours = int($1)
except IndexError:
delta_hours = 0
print(calculate_time(delta_hours))"
}
humanbytes()
{
local SIZE=$1
local UNITS="B KiB MiB GiB TiB PiB"
for F in $UNITS; do
local UNIT=$F
test ${SIZE%.*} -lt 1024 && break;
SIZE=$(echo "$SIZE / 1024" | bc -l)
done
if [ "$UNIT" == "B" ]; then
printf "%4.0f %s\n" $SIZE $UNIT
else
printf "%7.02f %s\n" $SIZE $UNIT
fi
}
get_container_images() {
local ns="${1:-oulib}" # Use argument as namespace, default to 'oulib' if none provided
echo "Image Usage Summary for $ns: $(date)"
echo "--------------------"
kubectl get pods -n "$ns" -o jsonpath="{.items[*].spec.initContainers[*].image} {.items[*].spec.containers[*].image}" \
| tr -s "[[:space:]]" "\n" \
| grep -v quay \
| grep -v "^$" \
| sort \
| uniq -c \
| sort -nr \
| awk '{
split($2, parts, "/");
repo = parts[length(parts)];
split(repo, name_tag, ":");
shortname = name_tag[1];
printf "%-3s - %-18s : %s\n", $1, shortname, $2
}'
}
pod_images() {
local ns="${1:-oulib}" # default to 'oulib' if no argument is given
kubectl get pods -n "$ns" --no-headers \
--output=custom-columns="IMAGE:.spec.containers[*].image,NAME:.metadata.name" \
| grep -v -e hub -e proxy \
| awk '{
split($1, a, "/");
split(a[length(a)], b, ":");
printf "%-20s %-30s\n", b[1], $2
}'
}
nautuse() {
clear
# First section: container images summary
get_container_images "$1" # pass namespace if provided
echo
# Pause for user
read -rep $'Press enter q to quit or enter l to see user images. \n' dummy
if [[ $dummy == 'q' ]] || [[ $dummy == 'q' ]] || [[ $dummy == '' ]]; then
return
fi
echo
echo " image user"
# Second section: pod images
pod_images "$1"
}