-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
executable file
·2208 lines (2028 loc) · 77.9 KB
/
.bashrc
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# sudo usermod $UESR -a -G wheel
#sudoers# %wheel ALL=(ALL) ALL
#sudoers# Defaults timestamp_timeout=-1
# sudo openvpn --config ~/.ssh/client.ovpn
# login=jlu password=windowsPassword
# ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519
# ssh-keygen -o -t rsa -b 4096 -f ~/.ssh/id_rsa
# ## support xauth pour les applis X:
# echo "session optional pam_xauth.so" >> /etc/pam.d/su
# sudo sysctl -w vm.swappiness=1
# kernel boot options : nomodeset nouveau.modeset=0 pci=noaer pci=nomsi libata.noacpi=1 nvidia-drm.modeset=1
# ubuntu nvidia: echo "options nvidia-drm modeset=1" >> /etc/modprobe.d/nvidia.conf
# ubuntu: install nvidia and blacklist nouveau; vi /etc/default/grub # GRUB_CMDLINE_LINUX="pci=nomsi" ; sudo update-grub;
# lspci -nnk | grep -i vga -A3 | grep 'in use'
# hwinfo --gfxcard
# fix sound ubuntu
# pulseaudio -k # kill the process to force restart by systemd
# sudo alsa force-reload
# blkid -c /dev/null -o list
# lsblk -o name,label,partlabel,size,uuid,mountpoint
# listsmb="//prc-01-eu/DATAS //pp-prd-01-scus/logs //pp-prc-01-scus/logs //ppeu-prc-01/logs //ppeu-prd-01/logs //172.31.1.2/public"
# sudo mount.cifs //prc-01-eu/DATAS /mnt/windows -o sec=ntlm,noperm,nounix,dir_mode=0777,file_mode=0777,user=jlu,dom=GEO6,vers=2.1
# sudo mount.cifs //172.31.1.2/public /mnt/echange -o sec=ntlm,noperm,nounix,dir_mode=0777,file_mode=0777,user=jlu,dom=GEO6,vers=2.1
# sudo mount -t ntfs -o "rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other" "/dev/sdc2" "/mnt/ntfs-d"
# egrep -v '^#' /etc/systemd/journald.conf
# SystemMaxUse=3G
# MaxRetentionSec=1month
# MaxFileSec=1week
# sudo journalctl --rotate
# sudo journalctl --vacuum-time=10minute
# ecryptfs-simple /path/to/foo /path/to/bar
# sudo certbot certonly --standalone --preferred-challenges http -d example.com
# sudo certbot certonly --webroot -w /var/www/example -d www.example.com ### /var/www/example is a directory
# tar compress parallel
# tar -I "xz -T0" -cf archive.tar.xz ./file.csv
# XZ_OPT='-T0 -9' tar -cJf archive.tar.xz ./file.csv
export XZ_OPT='-T0'
# echo "set zoom level on an anker webcam" ; v4l2-ctl --list-devices ; v4l2-ctl --device /dev/video4 --list-ctrls ; v4l2-ctl --device /dev/video4 --set-ctrl=zoom_absolute=400
# docker run -d --name=netdata -p 19999:19999 -v netdataconfig:/etc/netdata -v netdatalib:/var/lib/netdata -v netdatacache:/var/cache/netdata -v /etc/passwd:/host/etc/passwd:ro -v /etc/group:/host/etc/group:ro -v /proc:/host/proc:ro -v /sys:/host/sys:ro -v /etc/os-release:/host/etc/os-release:ro --restart unless-stopped --cap-add SYS_PTRACE --security-opt apparmor=unconfined netdata/netdata
test -s ~/.alias && . ~/.alias || true
# Source global definitions
if [ -e /etc/bashrc ]; then
source /etc/bashrc
fi
if [ -e ~/.xsh ]; then
source ~/.xsh
fi
if [[ -e ~/.secret ]]; then
source ~/.secret
fi
# Ubuntu 22.04 desktop
bind 'set enable-bracketed-paste off' 2>/dev/null
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
export myshell=$(which bash)
export kernelver=$(uname -s)$(uname -r)
if [[ ! -z $(which lsb_release 2>/dev/null) ]] ; then
export linuxDistro=`lsb_release -i | awk -F ':' '{print $2}' | xargs echo`
export linuxDistroVer=`lsb_release -d | awk -F ':' '{print $2}' | xargs echo`
fi
#export osname=`python -c 'import sys; sys.path.append("/usr/lib/python2.6/site-packages/"); from ambari_commons import OSCheck; print OSCheck.get_os_family()'`
#export osversion=`python -c 'import sys; sys.path.append("/usr/lib/python2.6/site-packages/"); from ambari_commons import OSCheck; print OSCheck.get_os_major_version()'`
export platform=$(uname -s)
if [[ "$USER" = "root" ]]; then
export HOME=/root
fi
#export user=$USER
if [[ -z $HOST && -z $HOSTNAME ]] ; then
export HOST="$(uname -n)"
export HOSTNAME="$(uname -n)"
elif [[ -z $HOST && ! -z $HOSTNAME ]] ; then
export HOST=$HOSTNAME
elif [[ ! -z $HOST && -z $HOSTNAME ]] ; then
export HOSTNAME=$HOST
fi
export tabulation=`echo -e "\t"`
# export pyver=`python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(f"{major}.{minor}")'`
#============================================================
export mylistSsh=$(grep -v -e "^#" -e "localhost" /etc/hosts | sed '/^$/d' | grep "^[0-9]" | awk '{print $2}' | sort | uniq)
export allhost=($(grep -v -e "^#" -e "localhost" /etc/hosts | sed '/^$/d' | grep "^[0-9]" | awk '{print $2}'))
export allip=($(grep -v -e "^#" -e "localhost" /etc/hosts | sed '/^$/d' | grep "^[0-9]" | awk '{print $1}'))
#============================================================
# Functions (1)
#
##
# serialize_array
# Serializes a bash array to a string, with a configurable seperator.
#
# $1 = source varname ( contains array to be serialized )
# $2 = target varname ( will contian the serialized string )
# $3 = seperator ( optional, defaults to $'\x01' )
#
# example:
#
# my_arry=( one "two three" four )
# serialize_array my_array my_string '|'
# declare -p my_string
#
# result:
#
# declare -- my_string="one|two three|four"
#
function serialize_array() {
declare -n _array="${1}" _str="${2}" # _array, _str => local reference vars
local IFS="${3:-$'\x01'}"
# shellcheck disable=SC2034 # Reference vars assumed used by caller
_str="${_array[*]}" # * => join on IFS
}
##
# deserialize_array
# Deserializes a string into a bash array, with a configurable seperator.
#
# $1 = source varname ( contains string to be deserialized )
# $2 = target varname ( will contain the deserialized array )
# $3 = seperator ( optional, defaults to $'\x01' )
#
# example:
#
# my_string="one|two three|four"
# deserialize_array my_string my_array '|'
# declare -p my_array
#
# result:
#
# declare -a my_array=([0]="one" [1]="two three" [2]="four")
#
function deserialize_array() {
IFS="${3:-$'\x01'}" read -r -a "${2}" <<<"${!1}" # -a => split on IFS
}
unalias sudisp 2>/dev/null
sudisp()
{
usr=$1
echo $DISPLAY
xauth list $DISPLAY
xdis=`xauth list $DISPLAY | grep -v '^#' | head -1`
dis=$DISPLAY
sudo su - $usr
export DISPLAY=$dis
xauth add $xdis
}
unalias sourceprop 2>/dev/null
sourceprop()
{
javaproperties=$1
source <(awk 'BEGIN {
FS="=";
n="";
v="";
c=0; # Not a line continuation.
}
/^#/ { # The line is a comment. Breaks line continuation.
c=0;
next;
}
/\\$/ && (c==0) && (NF>=2) { # Name value pair with a line continuation...
e=index($0,"=");
n=substr($0,1,e-1);
v=substr($0,e+1,length($0) - e - 1); # Trim off the backslash.
c=1; # Line continuation mode.
next;
}
/^[^\\]+\\$/ && (c==1) { # Line continuation. Accumulate the value.
v= "" v substr($0,1,length($0)-1);
next;
}
((c==1) || (NF>=2)) && !/^[^\\]+\\$/ { # End of line continuation, or a single line name/value pair
if (c==0) { # Single line name/value pair
e=index($0,"=");
n=substr($0,1,e-1);
v=substr($0,e+1,length($0) - e);
} else { # Line continuation mode - last line of the value.
c=0; # Turn off line continuation mode.
v= "" v $0;
}
# Make sure the name is a legal shell variable name
gsub(/[^A-Za-z0-9_]/,"_",n);
# Remove newlines from the value.
gsub(/[\n\r]/,"",v);
print n "=\"" v "\"";
n = "";
v = "";
}
END {
}' ${javaproperties})
}
# =======================
sedblank() {
sed '/^[[:space:]]*$/d' $1 | sed 's/[[:blank:]]*$//'
}
# =======================
# =======================
check_init() {
local key=$(echo $1)
if [[ -z ${!key} ]]; then
echo "ERROR ! $key empty"
exit 999
fi
}
# only export variable if it is undefined
export_protected()
{
local key=`echo $1 | awk -F '=' '{print $1}'`
if [[ -z ${!key} ]]; then
#declare -x "$1"
export $1
fi
}
# =======================
unalias exporte 2>/dev/null
# avoid to export keys (like PATH or LD_LIBRARYPATH) to value pointing to non existing path or including duplicates
exporte()
{
# usage:
# exporte titi=/usr/bin:/opt/bin ; echo $titi ; exporte titi=$titi:~/bin ; echo $titi; exporte titi=$titi:/trou/duc
key=`echo $1 | awk -F '=' '{print $1}'`
valOld=$(echo ${!key})
vals=$(echo $1 | awk -F '=' '{print $2}')
valArr=($(echo $vals | sed 's/^://' | sed 's/:/ /g' ))
unset valstrtmp
for val in ${valArr[@]}; do
if [[ -e $val || ! -z $(ls $val 2>/dev/null) ]] ; then #if path exists
if [[ -z $valstrtmp ]] ; then #key is initialized if void
valstrtmp=$val
elif [[ -z $(echo $valstrtmp | grep -e "^$val:" -e ":$val:" -e ":$val$") ]] ; then #else it is incremented
valstrtmp=$valstrtmp:$val
fi
# else
# echo "Warning ! path $val does not exist and was ignored for key $key by function exporte"
fi
done
if [[ -z $valstrtmp && ! -z $valOld && -e $valOld ]]; then
export $key=$valOld
else
export $key=$valstrtmp
fi
}
unalias export_no_void 2>/dev/null
# avoid to export keys (like PATH or LD_LIBRARYPATH) to value pointing to non existing path or including duplicates
export_no_void()
{
# usage:
# exporte titi=/usr/bin:/opt/bin ; echo $titi ; exporte titi=$titi:~/bin ; echo $titi; exporte titi=$titi:/trou/duc
key=`echo $1 | awk -F '=' '{print $1}'`
vals=$(echo $1 | awk -F '=' '{print $2}')
valArr=($(echo $vals | sed 's/^://' | sed 's/:/ /g' ))
unset valstrtmp
for val in ${valArr[@]}; do
if [[ -e $val || ! -z $(ls $val 2>/dev/null) ]] ; then #if path exists
if [[ -z $valstrtmp ]] ; then #key is initialized if void
valstrtmp=$val
elif [[ -z $(echo $valstrtmp | grep -e "^$val:" -e ":$val:" -e ":$val$") ]] ; then #else it is incremented
valstrtmp=$valstrtmp:$val
fi
# else
# echo "Warning ! path $val does not exist and was ignored for key $key by function exporte"
fi
done
if [[ ! -z $valstrtmp ]]; then
export $key=$valstrtmp
fi
}
unalias myip 2>/dev/null
myip()
{
ip route get 8.8.8.8 2>/dev/null | awk '{ for(i=1; i<NF; i++) { if($i == "src") {print $(i+1); exit} } }'
# ip addr show dev eth1 primary | awk '/(inet .*\/)/ { print $2 }' | cut -d'/' -f1
}
alias ippub="curl i-p.show"
alias ippubEC2="curl http://169.254.169.254/latest/meta-data/public-ipv4"
unalias spfy 2>/dev/null
spfy()
{
if [[ $# -eq 0 ]]; then
# spotify pause
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
elif [[ "$1" = "n" ]]; then
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
else
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
fi
}
unalias disownall 2>/dev/null
disownall()
{
list=$(jobs -l 2>/dev/null | awk '{print $2}')
if [[ ! -z $list ]] ; then
echo $list
disown $list
fi
}
unalias dateDaystoMs 2>/dev/null
dateDaystoMs()
{
if [[ $# -eq 1 ]]; then
day=$1
echo "$day *24.0*60.0*60.0*1000.0" | bc
else
echo "ERROR ! 1/ day"
fi
}
unalias dateJtoH 2>/dev/null
dateJtoH()
{
if [[ $# -eq 2 && $2 -le 366 ]]; then
year=$1
day=$2
date -d "${year}-01-01 +$(( ${day} - 1 ))days" +%Y-%m-%d
else
echo "ERROR ! 1/ year 2/ day Julian"
fi
}
unalias dateJtoEpoch 2>/dev/null
dateJtoEpoch()
{
if [[ $# -eq 2 && $2 -le 366 ]]; then
year=$1
day=$2
date -d "${year}-01-01 +$(( ${day} - 1 ))days" +%s
else
echo "ERROR ! 1/ year 2/ day Julian"
fi
}
unalias dateEpochToH 2>/dev/null
dateEpochToH()
{
date -d @$1 +%Y-%m-%dT%H:%M:%S' '%z
}
unalias dateDaysFromEpoch 2>/dev/null
dateDaysFromEpoch()
{
date -d @$(echo "$1 * 86400" | bc) +%Y-%m-%d' '%z
}
unalias dateEpoch 2>/dev/null
dateEpoch()
{
date +%s
}
alias dateEpochMs="date +%s%3N"
unalias dateEpochUsToH 2>/dev/null
dateEpochUsToH()
{
v=`echo $1 / 1000000 | bc`
date -d @$v +%Y-%m-%dT%H:%M:%S.%N' '%z
}
unalias dateEpochmicros 2>/dev/null
dateEpochUs()
{
echo $(($(date +%s%N)/1000))
}
unalias gitlabci 2>/dev/null
gitlabci()
{
# arg $1 is the name of the stage in your file .gitlab-ci.yml
docker run --rm -w $PWD -v $PWD:$PWD -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest exec docker $1
}
unalias poetrya 2>/dev/null
poetrya()
{
poetryaPath=$1
if [[ -e $poetryaPath/pyproject.toml ]]; then
pwd
cd $poetryaPath
poetry env list
poetry env info --path
poetry shell
elif [[ -e $poetryaPath/bin/activate ]]; then
pwd
# source $poetryaPath/bin/activate # commented out by conda initialize
else
poetrylist
echo "ERROR ! poetry env not found at $poetryaPath"
fi
}
unalias poetrylist 2>/dev/null
poetrylist()
{
if [[ -e pyproject.toml ]]; then
poetry env list
poetry env info --path
fi
poetryList=`poetry config virtualenvs.path`
ls -lad $poetryList/*-py[0-9]*
}
unalias dockernodexporter 2>/dev/null
dockernodexporter()
{
ss -tulpn | grep 9100
nodeuid=`cat /etc/passwd | grep node_exporter | awk -F ':' '{print $3}'`
docker run -d -p 9100:9100 --user ${nodeuid}:${nodeuid} -v "/:/hostfs" --net="host" prom/node-exporter:v0.18.1 --path.rootfs=/hostfs
ss -tulpn | grep 9100
}
# Function dockercleanv
unalias dockercleanv 2>/dev/null
dockercleanv()
{
pattern=`echo "$*" | sed -e 's: :\\\|:g'`
docker volume ls 2>&1 | grep -- "$pattern"
parent=`docker volume rm $* 2>&1 | grep 'volume is in use' | awk '{print $NF}' | tr -d '[]'`
parent=`echo $parent`
if [[ ! -z $parent ]]; then
for id in $parent; do
docker inspect $id | jq '.[] | .Name, .Id '
done
docker stop $parent
docker rm $parent
docker volume rm $*
fi
echo "clean all with : dockercleanv \$(docker volume ls | awk '{print $2}' | grep -v VOLUME)"
}
alias dockerips="docker inspect -f '{{.Name}} : {{.NetworkSettings.IPAddress }} {{range .NetworkSettings.Networks}} - {{.IPAddress}}{{end}}' \$(docker ps -aq)"
# Function dockercleani
unalias dockercleani 2>/dev/null
dockercleani()
{
docker images | awk '$2 ~ /<none>/'
docker images | awk '$2 ~ /<none>/' | awk '{print $3}' | grep -v IMAGE | xargs docker rmi -f
echo "you may want to also run to clean networks and more : docker system prune"
}
# Function dockerclean
unalias dockerclean 2>/dev/null
dockerclean()
{
docker rm $(docker ps -qa --filter status=exited)
docker volume prune -f
#docker image prune -a -f
#docker images | awk '$2 !~ /^[[:digit:]]*$|^[0-9.]*$|latest|master|base/'
#docker images | awk '$2 !~ /^[[:digit:]]*$|^[0-9.]*$latest|master|base/' | awk '{print $3}' | grep -v IMAGE | xargs docker rmi -f
}
unalias dockerbuild 2>/dev/null
dockerbuild()
{
myimage=$(basename `pwd`)
if [[ $# -eq 0 ]]; then
for f in $(ls *.dockerfile); do
echo "===================>>> docker build image described by $f to $myimage:${f%.dockerfile}"
cat $f > ${f%.dockerfile}.log
docker build --progress=plain -t $myimage:${f%.dockerfile} -f $f . 2>&1 | tee -a ${f%.dockerfile}.log
docker image prune -f
done
f=Dockerfile
else
f=$1
fi
if [[ -e $f ]]; then
echo "===================>>> docker build image described by $f to $myimage:${f%.dockerfile}"
cat $f > ${f%.dockerfile}.log
docker build --progress=plain -t $myimage:${f%.dockerfile} -f $f . 2>&1 | tee -a ${f%.dockerfile}.log
fi
}
unalias dockerlog 2>/dev/null
dockerlog() {
local opt=""
local arg=10
local str=.
if [[ $# -ge 1 ]]; then
arg=$1
fi
if [[ $# -ge 2 ]]; then
str=$2
fi
if [[ ! -z $(echo $arg | grep "[[:alpha:]]") ]]; then
opt="--since $arg"
else
opt="-n $arg"
fi
for did in `docker ps | awk '{print $NF}'| grep -v NAMES | grep -i $str`; do
echo "================== $did =================" ;
echo "docker logs $opt $did 2>&1"
docker logs $opt $did 2>&1
done
}
unalias dockerlogsOLD 2>/dev/null
dockerlogsOLD() {
if [[ $# -eq 0 ]]; then
echo "ERROR : please providing a query string to grep !"
else
#journalctl -u docker CONTAINER_ID=$1 | grep -i -v -e Elasticsearch -v -e ']: $' -v -e ' No living connections' -e ' No living connections' -e 'GET /healthz' -e 'lib.request_handlers.authentication - info - No bearer token found on request'
journalctl -u docker CONTAINER_ID=$1
echo "journalctl -u docker --since=-5m CONTAINER_ID=$1"
fi
}
unalias dockerjlog 2>/dev/null
dockerjlog() {
if [[ $# -eq 0 ]]; then
echo "ERROR : please providing a query string to grep !"
else
journalstr=""
for str in $* ; do
ids=`docker ps | grep $str | awk '{print $1}'| grep -v CONTAINER`
if [[ ! -z $ids ]]; then
for id in $ids; do
journalstr="CONTAINER_ID=$id $journalstr"
done
fi
done
#journalctl -u docker --since=-5m $journalstr | grep -i -v -e Elasticsearch -v -e ']: $' -v -e ' No living connections' -e ' No living connections' -e 'GET /healthz' -e 'lib.request_handlers.authentication - info - No bearer token found on request'
journalctl -u docker --since=-5m $journalstr
echo "journalctl -u docker --since=-5m $journalstr"
fi
}
unalias dockerhist 2>/dev/null
dockerhist() {
docker history --no-trunc "$1" | \
sed -n -e 's,.*/bin/sh -c #(nop) \(MAINTAINER .*[^ ]\) *0 B,\1,p' | \
head -1
docker inspect --format='{{range $e := .Config.Env}}
ENV {{$e}}
{{end}}{{range $e,$v := .Config.ExposedPorts}}
EXPOSE {{$e}}
{{end}}{{range $e,$v := .Config.Volumes}}
VOLUME {{$e}}
{{end}}{{with .Config.User}}USER {{.}}{{end}}
{{with .Config.WorkingDir}}WORKDIR {{.}}{{end}}
{{with .Config.Entrypoint}}ENTRYPOINT {{json .}}{{end}}
{{with .Config.Cmd}}CMD {{json .}}{{end}}
{{with .Config.OnBuild}}ONBUILD {{json .}}{{end}}' "$1"
}
# Function grepsrc
# Example of direct find cmd:
# find . -name "*.go" ! -name '*_doc_generated.go' ! \( -path '*/vendor/*' -o -path '*/test/*' -o -path '*/rbac/*' \) | xargs grep -ri --color leader
# find . -name "*.go" ! -name '*_doc_generated.go' ! \( -path '*/vendor/*' -o -path '*/test/*' -o -path '*/rbac/*' -o -path '*/metrics/*' -o -path '*/testing/*' \) | xargs grep -ri --color watch
unalias grepsrc 2>/dev/null
grepsrc()
{
searchpath=.
expression=''
opt=''
if [[ $# -eq 3 ]] ; then
searchpath=$1
opt=$2
expression=$3
elif [[ $# -eq 2 ]] ; then
opt=$1
expression=$2
else
expression=$1
fi
find $searchpath ! \( -path '*/node_modules/*' -o -path '*/vendor/*' \) \( -name '.*.yaml' -o -name '.*.yml' -o -name '*.kt' -o -name '*.yml' -o -name '*.go' -name '*.for' -o -name '*.f' -o -name '*.F' -o -name '*.h' -o -name '*.F90' -o -name '*.f90' -o -name '*.m' -o -name '*.M' -o -name '*.py' -o -name '*.c' -o -name '*.C' -o -name '*.cpp' -o -name '*.CPP' -o -name '*.c++' -o -name '*.C++' -o -name '*.H' -o -name '*.inc' -o -name '*.?sh' -o -name '*.??sh' -o -name '*.sh' -o -name '*.java' -o -name '*.scala' -o -name '*.julia' -o -name '*.js' -o -name '*.go' -o -name '*.php' -o -name '*.perl' -o -name '*.sbt' -o -name 'pom.xml' -o -name '*.t' \) -print 2>/dev/null | xargs grep --color -s $opt -- $expression
}
# end Function grepsrc
# Function grepjs
unalias grepjs 2>/dev/null
grepjs()
{
searchpath=.
expression=''
opt=""
if [[ $# -eq 3 ]] ; then
opt=$1
expression=$2
searchpath=$3
elif [[ $# -eq 2 ]] ; then
expression=$1
searchpath=$2
else
expression=$1
fi
find $searchpath -name '*.js' -print 2>/dev/null | xargs grep --color -s $opt -- $expression
}
# end Function
# Function greppy
unalias greppy 2>/dev/null
greppy()
{
searchpath=.
expression=''
opt=""
if [[ $# -eq 3 ]] ; then
opt=$1
expression=$2
searchpath=$3
elif [[ $# -eq 2 ]] ; then
expression=$1
searchpath=$2
else
expression=$1
fi
find $searchpath \( -name '*.py' -o -name '*.?sh' -o -name '*.??sh' -o -name '*.sh' \) -print 2>/dev/null | xargs grep --color -s $opt -- $expression
}
# end Function
unalias inList 2>/dev/null
inList()
{
local search="$1"
shift
local list=("$@")
for file in "${list[@]}" ; do
[[ "$file" == "$search" ]] && echo "1" && return
done
echo "0"
}
# Function grepc
unalias grepc 2>/dev/null
grepc()
{
list=$(find ./ \( -name "./.*" -prune -name "*/target/*" -o -print \) 2>/dev/null | xargs grep --binary-files=without-match --no-message -s -c -i $1 | grep -v ":0" | awk -F ":" '{sum+=$NF} END {print sum}')
}
# end Function
# Function
unalias psup 2>/dev/null
psup()
{
time="00:00"
elaspedSeconds=0
if [[ $# -eq 1 ]] ; then
psargument=$1
time=`ps -eo pid,etime,time,comm,args | grep -v " grep " | grep $psargument | awk '{ print $2}' | tail -1`
# minute: mm:ss
# hours: hh:mm:ss
# days: d-hh:mm:ss
#echo $time
days=0
hours=0
minutes=0
seconds=0
if [[ $(echo $time | grep -c -- '\-') -gt 0 ]]; then
days=$(echo $time | awk -F '-' '{print $1}')
hours=$(echo $time | awk -F '-' '{print $2}' | awk -F ':' '{printf "%d\n", $1}' )
minutes=$(echo $time | awk -F '-' '{print $2}' | awk -F ':' '{printf "%d\n", $2}' )
seconds=$(echo $time | awk -F '-' '{print $2}' | awk -F ':' '{printf "%d\n", $3}' )
elif [[ $(echo $time | grep -o -- ':' | wc -l) -eq 2 ]]; then
hours=$(echo $time | awk -F ':' '{printf "%d\n",$1}' )
minutes=$(echo $time | awk -F ':' '{printf "%d\n",$2}' )
seconds=$(echo $time | awk -F ':' '{printf "%d\n",$3}' )
elif [[ $(echo $time | grep -o -- ':' | wc -l) -eq 1 ]]; then
minutes=$(echo $time | awk -F ':' '{printf "%d\n", $1}' )
seconds=$(echo $time | awk -F ':' '{printf "%d\n", $2}' )
fi
elaspedSeconds=$(python -c "print (($days*24+$hours)*60+$minutes)*60+$seconds")
fi
echo $elaspedSeconds
}
# end Function
# Function zpop
unalias zpop 2>/dev/null
zpop()
{
max=`dirs | tail -1 | awk '{ print $1 }'`
max=`echo $max`
target=$1
i=$max
while [[ $i -gt $target && $i -gt 1 ]] ; do
popd $i 2>&1 >/dev/null
i=$(($i-1))
done
}
# end Function zpop
# Function lsd
unalias lsd 2>/dev/null
lsd()
{
if [[ $# -ge 0 ]]; then
path=$1
else
path=$(pwd)
fi
\ls -l $path | awk 'NR!=1 && /^d/ {print $NF}'
}
# end Function lsd
# Function findfor
unalias findfor 2>/dev/null
findfor()
{
find $1 \( -name '*.for' -o -name '*.f' -o -name '*.F' -o -name '*.h' -o -name '*.F90' -o -name '*.f90' \) -print 2>/dev/null
}
# end Function findfor
# Function upper_case
unalias i_upper_case 2>/dev/null
i_upper_case()
{
echo $1 | tr '[:lower:]' '[:upper:]'
}
#
# Function ffind
unalias ffind 2>/dev/null
ffind()
{
zn=$(echo $1 | tr '[:lower:]' '[:upper:]')
find . \( -name "*$1*" -o -name "*$zn*" \) 2>/dev/null
}
# end Function ffind
# Function digit2
unalias digit2 2>/dev/null
digit2()
{
# if available: typeset -Z2 $1
echo $1 |awk ' { printf "%02d\n", $0 } '
}
# End Function digit2
# Function digit3
unalias digit3 2>/dev/null
digit3()
{
# if available: typeset -Z2 $1
echo $1 |awk ' { printf "%03d\n", $0 } '
}
# End Function digit3
# Function digit4
unalias digit4 2>/dev/null
digit4()
{
# if available: typeset -Z4 $1
echo $1 |awk ' { printf "%04d\n", $0 } '
}
# End Function digit4
# Function digit6
unalias digit6 2>/dev/null
digit6()
{
# if available: typeset -Z4 $1
echo $1 |awk ' { printf "%06d\n", $0 } '
}
# End Function digit6
# Function digitn
unalias digitn 2>/dev/null
digitn()
{
# if available: typeset -Z$2 $1
i=0000000000000000000000000000000000000$1
n=1
fmt=''
while [[ $n -le $2 && $n -le 16 ]] ; do
fmt=$fmt'.'
n=$(($n+1))
done
fmt='.*\('$fmt'\)'
expr $i : "$fmt"
}
# End Function digitn
# Function mediaexp
unalias mediaexp 2>/dev/null
mediaexp()
{
prefix=''
followlinks=1
if [[ $# -eq 1 ]] ; then
dest=$1
elif [[ $# -eq 2 ]] ; then
dest=$1
followlinks=$2
elif [[ $# -eq 3 ]] ; then
dest=$1
prefix=$3
else
dest=/tmp
fi
if [[ ! -d $dest ]] ; then
echo "Error ! directory $d does not exist"
else
if [[ $followlinks -eq 1 || $followlinks = "lnk" || $followlinks = "-L" ]] ; then
list=`find -L . \( -name "*.gif" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.avi" -o -name "*.eps" -o -name "*.ps" -o -name "*.pdf" -o -name "trac_resi*.log" -o -name "gplot*.log" ! -name "*-it[0-9][0-9][0-9][0-9].jpg" ! -name "*-it[0-9][0-9][0-9][0-9][0-9][0-9].jpg" \) -type f`
else
list=`find -H . \( -name "*.gif" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.avi" -o -name "*.eps" -o -name "*.ps" -o -name "*.pdf" -o -name "trac_resi*.log" -o -name "gplot*.log" ! -name "*-it[0-9][0-9][0-9][0-9].jpg" ! -name "*-it[0-9][0-9][0-9][0-9][0-9][0-9].jpg" \) -type f`
fi
list=$(echo $list)
echo $list
for f in $list ; do
if [[ $dest != $(dirname ${f#./} | tr -s '/' ' ' | awk '{ print $1 }') && ! -z $(echo $f | grep -v -- -it[0-9][0-9][0-9][0-9].jpg | grep -v -- -it[0-9][0-9][0-9][0-9][0-9][0-9].jpg) ]] ; then
nf=$(echo "$prefix${f#./}" | sed 's:\.\/::g' | sed 's:\/:-:g' )
#cp $f $dest/$nf
#echo "cp $f $dest/$nf"
rsync -tu $f $dest/$nf
echo "rsync -tu $f $dest/$nf"
fi
done
echo "Copy in $dest OK"
fi
}
unalias sshi 2>/dev/null
sshi() {
i=$1
af=`echo ${i} |cut -c 1`
if [[ `echo "${HOSTNAME}" | tr '[:upper:]' '[:lower:]'` = "af${af}" ]]; then
echo "ssh -X 192.168.122.${i}"
ssh -X 192.168.122.${i}
else
echo "ssh -X -p 22${i} 192.168.60.20${af}"
ssh -X -p 22${i} 192.168.60.20${af}
fi
}
unalias sshRedir 2>/dev/null
sshRedir() {
port_ssh=22 #default on azure is 2200 instead of 22 normally
port_dist=80
port_local=$port_dist
if [[ $# -ge 1 ]] ; then
dest=$1
else
echo "need a destination host in input"
return
fi
if [[ $# -ge 2 ]] ; then
port_dist=$2
port_local=$port_dist
fi
if [[ $# -ge 3 ]] ; then
port_local=$3
fi
if [[ $# -ge 4 ]] ; then
port_ssh=$4
fi
netstat -anpe | grep ":$port_dist"
echo "sudo ssh -L $port_dist:localhost:$port_local -f -N ec2-user@$dest -p $port_ssh"
sudo ssh -L $port_dist:localhost:$port_local -f -N ec2-user@$dest -p $port_ssh
}
unalias jarls 2>/dev/null
jarls() {
if [[ $# -eq 1 ]] ; then
zjar=$1
else
echo "need a jar in input"
return
fi
jar tvf $zjar | grep ".class" | awk '{print $NF}' | sed "s/.class//g" | sed "s:\\$\\$:\\$ :g" | awk '{print $1}' | tr -s '/' '.' | sort | uniq
}
# list=$(jar tvf $zjar | grep ".class" | awk '{print $NF}' | sed "s/.class//g" | sed "s:\\$\\$:\\$ :g" | awk '{print $1}' | tr -s '/' '.' | sort | uniq) && for c in $list; do echo "log4j.appender.$c=INFO, graylog2"; done
unalias yarnFails 2>/dev/null
yarnFails() {
if [[ $# -ge 1 ]] ; then
yarn application -list -appStates ALL 2>/dev/null | sed "1,2d" | grep -e FAILED | grep -e $@
else
yarn application -list -appStates ALL 2>/dev/null | sed "1,2d" | grep -e FAILED
fi
}
unalias yarnq 2>/dev/null
yarnq() {
if [[ $# -ge 1 ]] ; then
yarn application -list -appStates ALL 2>/dev/null | sed "1,2d" | grep -e RUNNING -e ACCEPTED | grep -e $@
else
yarn application -list -appStates ALL 2>/dev/null | sed "1,2d" | grep -e RUNNING -e ACCEPTED
fi
}
unalias yarnk 2>/dev/null
yarnk() {
if [[ $# -ge 1 ]] ; then
for theapp in $@ ; do
yarn application -kill $theapp
done
fi
}
unalias yarnlog 2>/dev/null
yarnlog() {
if [[ $# -eq 1 ]] ; then
appid=$1
else
echo "need an applicationId in input"
return
fi
yarn logs -applicationId $appid > yarn_$appid.log 2>&1
echo "see file yarn_$appid.log"
}
unalias yarnchk 2>/dev/null
yarnchk() {
if [[ $# -eq 1 ]] ; then
appid=$1
else
echo "need an applicationId in input or file in *.log"
return
fi
tab=`echo -e "\t"`
if [[ $appid = ${appid%.log} || ! -e $appid ]] ; then
#yarn logs -applicationId $appid 2>/dev/null | grep -v '^#' | grep -e "^java.lang." -e "^$tab\at " -e " ERROR " -e "^java.io" -e "FileNotFound"
yarn logs -applicationId $appid > yarn_$appid.log 2>&1
flog=yarn_$appid.log
else
flog=$appid
fi
grep -v -e '^#' -v -e "disassociated! Shutting down." $flog | grep -e "^java.lang." -e " ERROR " -e "^java.io" -e "FileNotFoundException" -e "not serializable" -e "^$tab\at "
}
unalias offsetKafkaCompute 2>/dev/null
offsetKafkaCompute() {
yarn logs -applicationId $(yarnq | grep KAFKACompute | awk '{print $1}') -size -102400000 2>/dev/null | grep offset | tail -59 | awk -F '/' '{SUM+=$NF}END{print SUM}'
}
unalias offsetKafkaConsumer 2>/dev/null
offsetKafkaConsumer() {
groupid=topictest
nbpart=59
servers=dcos-kafka-32736118-0:9092,dcos-kafka-32736118-1:9092,dcos-kafka-32736118-2:9092
kafka-consumer-groups.sh --describe --new-consumer --bootstrap-server ${servers} --group ${groupid} > $tmpstr 2>&1
kafkaLag=`tail -${nbpart} $tmpstr | awk '{SUM+=$6}END{print SUM}'`
echo "Summed lag for consumer with groupid ${groupid} = $kafkaLag"
}
unalias hdiCheck 2>/dev/null
hdiCheck() {
for h in $mylistSshHdi ; do ssh $h ". /etc/profile ; uname -n; ls -lrt parquet*.log" 2>/dev/null; done
}
unalias hdiCheckTail 2>/dev/null
hdiCheckTail() {
for h in $mylistSshHdi ; do ssh $h ". /etc/profile ; uname -n; tail parquet*.log" 2>/dev/null; done
}
unalias ycheck 2>/dev/null
ycheck() {
python -c "from yaml import load, Loader; load(open('$1'), Loader=Loader)"
}
unalias zkmon 2>/dev/null
zkmon() {
export zkhost=$1
printf "${zkhost} " ; echo ruok | nc ${zkhost} 2181 ; echo ""
printf "${zkhost} " ; echo mntr | nc ${zkhost} 2181 ; echo ""
printf "${zkhost} " ; echo stat | nc ${zkhost} 2181 ; echo ""
}
# Mesos API
# curl -X GET http://$mesosMaster:5050/redirect # return leading master
# curl -X GET http://$mesosMaster:5050/flags # return master config
# curl -X GET http://$mesosMaster:5050/mesos/master/metrics/snapshot -o master_metrics.json
# curl -X GET http://$mesosMaster:5050/master/tasks -o master_tasks.json
# curl -X GET http://<marathon-ip>:8080/metrics
# curl -X GET http://<cluster>/system/v1/agent/<agent_id>/metrics/v0/<resource_path>
# curl -X GET http://<mesos-agent-ip>:5051/metrics/snapshot
# curl -X GET http://$mesosMaster:5050/master/frameworks -o master_frameworks.json
# see dcos tasks associated to a given framework id
# If you have a dc/os diagnostic bundle from the cluster before the teardown, you can see the tasks with something like this run from within one of the master dirs (substituting <framework-id> for the framework ID that you tore down):
# echo -e "ID NAME ROLE SLAVE_ID STATE\n $(jq -r '.frameworks[] | select(.id == "<framework-id>") | .tasks[] | "\(.id) \(.name) \(.role) \(.slave_id) \(.state)"' master_frameworks.json | sort -k 5)" | column -t
unalias lsMesosFramework 2>/dev/null
lsMesosFramework() {
export mesosMaster=$1
export frameworkId=$2