-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand-notes.txt
1742 lines (1439 loc) · 54.5 KB
/
command-notes.txt
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
function setup-mike() {
set -o vi
alias la="ls -al"
alias grep="grep --color=auto"
export PS1="\[\e[1;33\]m[\\u@\\h($(hostname --ip-address)): \\w]\\n\\$\[\e[m\] "
}
# setup env
export ZOOKEEPER=amb1.service.consul
export BROKERLIST=amb4.service.consul
sudo su root && cd ~;
systemctl stop sensor-stubs-bro
systemctl stop sensor-stubs-snort
systemctl stop sensor-stubs-yaf
service sensor-stubs stop
yum -y install redhat-lsb-core wget unzip curl scp mlocate vim screen && \
#yum -y install redhat-lsb-core wget unzip curl mlocate vim screen && \
yes | wget https://github.com/mmiklavc/linux-env/archive/master.zip && \
yes | unzip master.zip && \
yes | cp /root/linux-env-master/.vimrc /root/ && \
yes | cp /root/linux-env-master/.bashrc /root/.bashrc && \
yes | cp /root/linux-env-master/.screenrc /root/.screenrc && \
echo export METRON_HOST=node1 >> /root/.bashrc && \
echo export HDP_HOME=/usr/hdp/current >> /root/.bashrc && \
echo export KAFKA_HOME=/usr/hdp/current/kafka-broker >> /root/.bashrc && \
export SOLR_VERSION="6.6.2" && \
echo export SOLR_VERSION="$SOLR_VERSION" >> /root/.bashrc && \
echo export SOLR_HOME="/var/solr/solr-\${SOLR_VERSION}" >> /root/.bashrc && \
echo export ELASTIC_HOME="/usr/share/elasticsearch" >> /root/.bashrc && \
echo export KIBANA_HOME="/usr/share/kibana" >> /root/.bashrc && \
echo export ZOOKEEPER=\${METRON_HOST}:2181 >> /root/.bashrc && \
echo export BROKERLIST=\${METRON_HOST}:6667 >> /root/.bashrc && \
echo export STORM_UI=http://\${METRON_HOST}:8744 >> /root/.bashrc && \
echo export STORM_LOGS=/var/log/storm/workers-artifacts >> /root/.bashrc && \
echo export ELASTIC=http://\${METRON_HOST}:9200 >> /root/.bashrc && \
echo export ES_HOST=http://\${METRON_HOST}:9200 >> /root/.bashrc && \
echo export KIBANA=http://\${METRON_HOST}:5000 >> /root/.bashrc && \
export METRON_VERSION="0.7.2" && \
echo export METRON_VERSION="$METRON_VERSION" >> /root/.bashrc && \
echo export METRON_HOME="/usr/metron/\${METRON_VERSION}" >> /root/.bashrc && \
source /root/.bashrc && \
updatedb
# kill topologies
for i in profiler pcap bro__snort__yaf batch_indexing random_access_indexing;
do
storm kill $i;
done;
# kill topologies
for i in pcap profiler;
do
storm kill $i;
done;
# Example deprecation discussion
https://lists.apache.org/thread.html/6cfc883de28a5cb41f26d0523522d4b93272ac954e5713c80a35675e@%3Cdev.metron.apache.org%3E
# Example of the process we've used - deprecate in one release, remove in the next.
https://github.com/apache/metron/blob/master/Upgrading.md#060-to-070
https://github.com/apache/metron/blob/master/Upgrading.md#071-to-072
# Storm 1.0.1.2.5.3.0-37
export TERM=xterm-256color && set -o vi && alias la="ls -al" && export HDP_HOME=/usr/hdp/current
# on vagrant quickdev
export ZOOKEEPER=node1
export BROKERLIST=node1
export HDP_HOME="/usr/hdp/current"
export METRON_VERSION="0.4.3"
export METRON_HOME="/usr/metron/${METRON_VERSION}"
# reset topics and restart topologies
# ------
service sensor-stubs stop;
for topology in bro__snort__yaf enrichment profiler batch_indexing random_access_indexing;
do
storm kill $topology;
done;
for topic in bro yaf snort indexing enrichments pcap;
do
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --delete --topic $topic;
done;
sleep 20;
for topic in bro yaf snort indexing enrichments pcap;
do
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --create --partitions 1 --replication-factor 1 --topic $topic;
done;
service sensor-stubs start
# ------
# publish error data
while true;
do
echo "bro-garbage-" $(date "+%s") | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic bro;
echo "snort-garbage-" $(date "+%s") | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic snort;
sleep 2;
done;
# publish error data on a cycle
cycleval=1;
while true;
do
if [ $cycleval -ne 0 ];
then
datestamp=$(date "+%s");
cycleval=0;
else
cycleval=1;
fi;
echo "bro-garbage-" $datestamp | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic bro;
echo "snort-garbage-" $datestamp | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic snort;
echo "snort-garbage-" $datestamp | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic yaf;
sleep 2;
done;
====================
# other metron stuff
====================
# centos 7
systemctl start squid.service
====================
# elasticsearch
====================
# running the service
service elasticsearch start
# cluster health
curl -XGET 'http://node1:9200/_cluster/health?pretty=true'
# delete indexes
curl -XDELETE "http://node1:9200/squid*"
# list all indexes
curl -XGET "http://node1:9200/_cat/indices?v"
# check data in indexes
curl -XGET "http://node1:9200/yaf*/_search"
curl -XGET "http://ip-10-0-0-25.us-west-1.compute.internal:9200/squid*/_search?pretty=true"
# count
curl -XGET "http://node1:9200/bro*/_stats/docs?pretty=true"
# record stats for an index
curl -XGET "http://node1:9200/yaf*/_stats?pretty=true"
# set mappings for an index
curl -XPUT 'node1:9200/twitter?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}
'
curl -XPUT 'node1:9200/twitter?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
},
"mappings" : {
"tweet" : {
}
}
}
'
curl -XPUT 'http://node1:9200/_template/broketemplate_1' -d '
{
"template": "brokeindex_*",
"mappings": {
"brokeindex_doc": {
"dynamic_templates": [
{
"geo_location_point": {
"match": "enrichments:geo:*:location_point",
"match_mapping_type": "*",
"mapping": {
"type": "geo_point"
}
}
}
]
}
}
}
'
# check our busted template
curl -XGET 'http://node1:9200/_template/broke*?pretty=true
# add data to the busted bugger
curl -XPUT 'http://node1:9200/brokeindex_1/brokeindex_doc/1' -H 'Content-Type: application/json' -d'
{
"msg": "Broken template 1"
}
'
# get doc by ID
curl -XGET 'http://node1:9200/brokeindex_1/brokeindex_doc/1'
# xpack security
curl --user xpack_client_user:changeme <... remaining commands>
=======
Solr
=======
# create collection
cname = metaalert
su solr -c "${SOLR_HOME}/bin/solr create -c $cname -d ${METRON_HOME}/config/schema/$cname"
# delete collection
su solr -c "${SOLR_HOME}/bin/solr delete -c $cname"
===========
KAFKA
===========
# list kafka topics
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --list
# create kafka topics
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --create --partitions 1 --replication-factor 1 --topic $topic
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --create --topic squid --partitions 1 --replication-factor 1
# delete kafka topic
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --delete --topic yaf
# push data to kafka
cat foo.txt | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $BROKERLIST --topic squid
# read data from kafka
${HDP_HOME}/kafka-broker/bin/kafka-console-consumer.sh --bootstrap-server $BROKERLIST --topic squid --from-beginning
# delete hbase data
echo "truncate 'enrichment'" | hbase shell
# start topology
$METRON_HOME/bin/start_parser_topology.sh -z $ZOOKEEPER -s squid
# w/security
... --security-protocol PLAINTEXTSASL
# get offset data about a topic
/usr/hdp/current/kafka-broker/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list $BROKERLIST --topic pcap12 --security-protocol PLAINTEXTSASL --time -1 --offsets 1
# get topic info
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $ZOOKEEPER --topic pcap12 --describe
# get broker host info from zookeeper
echo "get /brokers/ids/1003" | /usr/hdp/current/kafka-broker/bin/zookeeper-shell.sh $ZOOKEEPER
# kafka acl
/usr/hdp/current/kafka-broker/bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=node1:2181 --list --topic yaf
# kafka consumer group info
watch -n 10 -d /usr/hdp/current/kafka-broker/bin/kafka-consumer-groups.sh --command-config=/tmp/consumergroup.config --describe --group bro_24_dryrun_parser --bootstrap-server $BROKERLIST --new-consumer
# note, --new-consumer is no longer needed
/usr/hdp/current/kafka-broker/bin/kafka-consumer-groups.sh --describe --group unixauthrouting_parser --bootstrap-server $BROKERLIST
# consumer group list
/usr/hdp/current/kafka-broker/bin/kafka-consumer-groups.sh --bootstrap-server $BROKERLIST --list
/usr/hdp/current/kafka-broker/bin/kafka-consumer-groups.sh --bootstrap-server $BROKERLIST --group indexing-ra --describe
# reset consumer group offset
/usr/hdp/current/kafka-broker/bin/kafka-consumer-groups.sh --bootstrap-server $BROKERLIST --group user_parser --topic user --reset-offsets --to-earliest
# homebrew notes
brew list installed
brew list <package> --versions
# pip notes
pip list
pip show <package>
pip install package==version
# pycapa
Here are some instructions for getting pycapa setup
Installing pycapa
====================
# env vars
PYCAPA_HOME=/opt/pycapa
PYTHON27_HOME=/opt/rh/python27/root
# Install these packages via yum (RHEL, CentOS)
# epel-release
# centos-release-scl
# "@Development tools"
# python27
# python27-scldevel
# python27-python-virtualenv
# libpcap-devel
# libselinux-python
# can run this command to loop
for item in epel-release centos-release-scl "@Development tools" python27 python27-scldevel python27-python-virtualenv libpcap-devel libselinux-python; do yum install -y $item; done
#Setup directories
mkdir $PYCAPA_HOME && chmod 755 $PYCAPA_HOME
# Create virtualenv
export LD_LIBRARY_PATH="/opt/rh/python27/root/usr/lib64"
cd $PYCAPA_HOME
${PYTHON27_HOME}/usr/bin/virtualenv pycapa-venv
#Install librdkafka
export PREFIX=/usr
wget https://github.com/edenhill/librdkafka/archive/v0.11.5.tar.gz -O - | tar -xz
cd librdkafka-0.11.5/
./configure --prefix=$PREFIX
make
make install
echo "$PREFIX/lib" >> /etc/ld.so.conf.d/pycapa.conf
ldconfig -v
# Copy pycapa
# copy incubator-metron/metron-sensors/pycapa from the Metron source tree into $PYCAPA_HOME on the node you would like to install pycapa on.
# Build it
cd ${PYCAPA_HOME}/pycapa
# activate the virtualenv
source ${PYCAPA_HOME}/pycapa-venv/bin/activate
pip install -r requirements.txt
python setup.py install
# kill other topologies
for i in batch_indexing bro enrichment profiler random_access_indexing snort; do storm kill $i; done
# Run it
cd ${PYCAPA_HOME}/pycapa-venv/bin
pycapa --producer --kafka-topic pcap --interface eth1 --kafka-broker $BROKERLIST
pycapa --consumer \
--max-packets 10000 \
--kafka-broker somedomain.com:6667 \
--kafka-topic pcap12 \
--kafka-offset begin \
-X security.protocol=SASL_PLAINTEXT \
-X sasl.kerberos.keytab=/etc/security/keytabs/metron.headless.keytab \
-X sasl.kerberos.principal=metron@EXAMPLE.COM \
-X group.id=metron \
| tshark -i - -Y malformed
# tshark
# install
yum -y install wireshark
# read from file
tshark -r pcap-data-201807292315-30b1403b0c944e269bd97fc1ee24055b+0004.pcap
# PCAP
/usr/metron/0.5.1/bin/pcap_query.sh fixed -df "yyyy-MM-dd-HH-mm" -st 2018-07-25-00-00 -et 2018-07-26-00-00 -rpf 1000 -ft 4
# mpack
ambari-server install-mpack --mpack= --verbose
ambari-server uninstall-mpack --mpack-name=metron-ambari.mpack
===========
ZOOKEEPER
===========
# push configs
$METRON_HOME/bin/zk_load_configs.sh -m PUSH -i $METRON_HOME/config/zookeeper/ -z $ZOOKEEPER
# read configs
$METRON_HOME/bin/zk_load_configs.sh -m DUMP -z $ZOOKEEPER
# read config type
$METRON_HOME/bin/zk_load_configs.sh -m DUMP -z $ZOOKEEPER -c GLOBAL
# read config type and name
$METRON_HOME/bin/zk_load_configs.sh -m DUMP -z $ZOOKEEPER -c PARSER -n bro
# pull configs local
$METRON_HOME/bin/zk_load_configs.sh -m PULL -o ${METRON_HOME}/config/zookeeper -z $ZOOKEEPER -f
====================
STORM
====================
# REST API
# kerberos
curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/cluster/summary
curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/summary
# get topology id
topology_name=bro; curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/summary | python -m json.tool | grep encodedId | grep ${topology_name} | awk -F: '{print $2}' | sed 's/ //g' | sed 's/,//g' | sed 's/\"//g'
# get topology info
topology_name=enrichment; encodedId=$(curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/summary | python -m json.tool | grep encodedId | grep ${topology_name} | awk -F: '{print $2}' | sed 's/ //g' | sed 's/,//g' | sed 's/\"//g') && curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/${encodedId} | python -m json.tool
# get bolt info
curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/bro-5-1494007692/component/BOLT | python -m json.tool | vim -
# putting them together
topology_name=bro; encodedId=$(curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/summary | python -m json.tool | grep encodedId | grep ${topology_name} | awk -F: '{print $2}' | sed 's/ //g' | sed 's/,//g' | sed 's/\"//g') && curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://hostname:8744/api/v1/topology/${encodedId}/component/spout
# Kerberos Storm via rest
# requires negotiate as shown below
>>> import requests
>>> r = requests.get("http://node1:8744/api/v1/topology/summary")
>>> r.status_code
401
>>> r.headers["www-authenticate"]
'Negotiate'
# silent mode - suppress status
curl -s
scp $(for file in metron-common-${METRON_VERSION}-uber.jar metron-data-management-${METRON_VERSION}-uber.jar metron-elasticsearch-storm-${METRON_VERSION}-uber.jar metron-enrichment-common-${METRON_VERSION}-uber.jar metron-enrichment-storm-${METRON_VERSION}-uber.jar metron-maas-service-${METRON_VERSION}-uber.jar metron-management-${METRON_VERSION}-uber.jar metron-parsers-${METRON_VERSION}-uber.jar metron-parsers-common-${METRON_VERSION}-uber.jar metron-parsing-storm-${METRON_VERSION}-uber.jar metron-pcap-backend-${METRON_VERSION}-uber.jar metron-performance-${METRON_VERSION}-uber.jar metron-profiler-repl-${METRON_VERSION}-uber.jar metron-profiler-spark-${METRON_VERSION}-uber.jar metron-profiler-storm-${METRON_VERSION}-uber.jar metron-rest-${METRON_VERSION}-uber.jar metron-solr-storm-${METRON_VERSION}-uber.jar stellar-common-${METRON_VERSION}-uber.jar; do find . -name $file; done) root@node1:/usr/metron/${METRON_VERSION}/lib
git checkout master
git pull
git checkout <fb>
git pull
git merge master
# deal with merge conflicts in a PR form
git commit --author="mmiklavc <michael.miklavcic@gmail.com>" -a -m "METRON-2239 Metron Automated backup and restore (mmiklavc) closes apache/metron#1546"
git push origin <fb>
# metron git apache
git pull
git pull --squash https://github.com/mmiklavc/metron METRON-478
git commit --author="mmiklavc <michael.miklavcic@gmail.com>" -a -m "METRON-478: Add Michael Miklavcic, Justin Leet, Nick Allen, and David Lyle to Metron website community page (mmiklavc via mmiklavc) closes apache/metron#287"
git push origin master
# merge some commits, but not all. Seems to work better than rebase and squash in some instances.
git reset --soft <commit>
git commit -m "Squashed commit"
# merge preferring the remote branch
git merge -X theirs <branch>
#droplet
ssh -D 2001 root@clevelandflash
# ssh fix on mac
# ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
sudo killall -HUP mDNSResponder
# scp recursive
scp -r sourcedir desthost:/destdir
# virtual-env
# deactivate your virtual env
deactivate
Apache Jira
-----------
# REST API
# Querying for a Jira
curl -D- -X GET -H "Content-Type: application/json" "https://issues.apache.org/jira/rest/api/2/search?jql=issue=METRON-923" | grep { | python -m json.tool
===============
LINUX SHELL
===============
man
---------------
# command number in parentheses
# e.g. GREP(1)
# (1) User Commands
# (2) System Calls
# (3) Library functions
# (4) Devices
# (5) File formats
# (6) Games and Amusements
# (7) Conventions and Miscellany
# (8) System Administration and Priveledged Commands
# (L) Local. Some programs install their man pages into this section instead
# (N) TCL commands
# search for man page entry
man -k <item to search for>
# look for files with imports not matching
for file in $(grep -lR --include \*.java "@Stellar" .)
do
if grep "^import" $file | grep -v " java\| org.apache.metron";
then
echo " $file matches"
echo "====================="
fi
done > /tmp/matchlist.txt
Shell Command Notes
-------------
sed -e 's/$/\r/' inputfile > outputfile # UNIX to DOS (adding CRs)
sed -e 's/\r$//' inputfile > outputfile # DOS to UNIX (removing CRs)
# in-place edit -i will add extension to bak file
sed -i 'extension' -e
# in-place with no backup file
sed -i 's/SELINUX=\(.*\)/SELINUX=disabled/' /etc/selinux/config
$(date +"%Y-%m-%d_%H-%M-%S-%N")
# newline with sed
sed -e 's/ /\'$'\n/g'
today=$(date +"%Y%m%d")
date -d @1438888564
# get date in seconds
date "+%s"
# diff commands
# diff from stdin
diff <(command 1) <(command 2)
# disk i/o io problems and troubleshooting
https://haydenjames.io/linux-server-performance-disk-io-slowing-application/
install ATOP - shows disk blocking %
# check disk speed
#To test write speed:
time dd if=/dev/zero bs=1024k of=tstfile count=1024
# To test read speed:
time dd if=tstfile bs=1024k of=/dev/null count=1024
# this one does it with purging
dd if=/dev/zero bs=1024k of=tstfile count=1024 && sudo purge && dd if=tstfile bs=1024k of=/dev/null count=1024 && rm tstfile
# https://haydenjames.io/web-host-doesnt-want-read-benchmark-vps/
dd if=/dev/zero of=diskbench bs=1M count=1024 conv=fdatasync
echo 3 | sudo tee /proc/sys/vm/drop_caches
# we run this next command 2x so first runs without buffer cache, 2nd runs with. 2nd should be much faster
dd if=diskbench of=/dev/null bs=1M count=1024
dd if=diskbench of=/dev/null bs=1M count=1024
rm diskbench
# to do this on Mac, install with Homebrew (brew install coreutils)
gdd if=/dev/zero of=diskbench bs=1M count=1024x5 conv=fdatasync
echo 3 | sudo tee /proc/sys/vm/drop_caches
# we run this next command 2x so first runs without buffer cache, 2nd runs with. 2nd should be much faster
gdd if=diskbench of=/dev/null bs=1M count=1024
gdd if=diskbench of=/dev/null bs=1M count=1024
rm diskbench
# DNS
dig google.com
# format JSON with Python
echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool
# format JSON with jq
echo '{ "hello" : "world", "foo" : [ { "old" : "maid" }, {"some" : "thing" }] }' | jq
{
"hello": "world",
"foo": [
{
"old": "maid"
},
{
"some": "thing"
}
]
}
# Diretory/file stuff - get dir/file part of string
dirname
basename
# sync yum repo locally
# r: repo id
reposync -r METRON-0.3.1
# search/check installed package
# "q" stands for "query", "a" stands for "all"
rpm -q man
rpm -qa | grep <whatever I care about>
#investigating installed packages
# like above, this will query all packages and filter by "metron"
rpm -qa|grep metron
# you can get info then for the installed packages
rpm -qi metron-common-0.3.1.1.1.0.0-63.el6.noarch
# alternatively, get information on which package installed a file on the local FS
rpm -qif /usr/hcp/current/metron/bin/prune_elasticsearch_indices.sh
# for not installed packages, you can do this (p=physical package file name)
rpm -qip foo.rpm
# install rpm
rpm -ivh <rpmname>
# view rpm contents by package filename
rpm -qlp <rpmname>
# view rpm contents for installed package
rpm -ql metron_1_1_0_0_71-config
# show just packages from specific repo
yum --disablerepo "*" --enablerepo "rpmforge" list available
Use { and } instead of ( and ) if you do not want Bash to fork a subshell. (is this accurate?)
# redirect all output and background the process
nohup ./myprocess.sh > logfile.txt 2>&1 &
# running commands in sequence
------------------------------
# if a returns zero exit code, then b is executed.
a && b
# if a returns non-zero exit code, then b is executed.
a || b
# a is executed and then b is executed.
a ; b
# nested commands and escaping
echo -e "select `echo -e \"eat \`echo -e \\"\nat\\"\`\njoes\"` me"
# result:
select eat
at
joes me
====================
screen commands
====================
http://aperiodic.net/screen/quick_reference
https://blog.bartbania.com/raspberry_pi/linux-screen/
# reorder windows
ctrl-a :number x
# rename session
ctrl-a :sessionname newSessionName
# set width, d=display size, w=window
ctrl-a :width -w|d 100
image manipulation
------------------
convert +append image1.jpeg image2.jpeg newimage.jpeg
# macports
sudo port select --list scala
sudo port select --set scala scala2.11
disk usage and info on partitions and mounts
----------
http://www.thegeekstuff.com/2013/01/mount-umount-examples/?utm_source=tuicool
mount
lsblk
df -Ta
# human readable 1024 - information about the partitions and their mount points
df -h
# human readable 1000
df -H
# list paritition current dir is on
df -h .
df -k
df -aTh
du -hcs
# list -s=summary only, x=skip diff file sys
du -hsx * | sort -rh | head -10
du -h
# list open files
lsof
# list disks/devices
fdisk -l
/dev/sdaN (N is device number)
# read file
echo $(<myfile.txt)
myfilevar=`<myfile.txt`
# echo NO newlines
echo $myvar
# echo WITH newlines preserved
echo "$myvar"
# loop on array index
for i in ${!args[@]}; do
echo $i
done
get filename
stat %n some_file
#append to array
arr=()
arr+=('someval')
arr+=('anotherval')
# check vars when set -u is enabled
if [[ -n "${1-}" ]]; then
$'command' - you can use ANSI C like strings, e.g. myvar=$'\001'
vs
$(command)
# adding numbers
$(( $a + $b ))
# looping values
for i in 1 2 3 4 5; do
echo $i
done
#debugging on
set -x
#debugging off
set +x
# web commands
curl -OL http://myurl/myfile.py
wget -O /outdir/file.txt http://someurl.com
Linux user management, sudo, su
-------------------
# enable directory expansion from variable (disabled default bash >= 4.2)
shopt -s direxpand
# commands as users
sudo -su pi /bin/bash
sudo -u <username> <command>
sudo -u username2 -H sh -c "cd /home/$USERNAME/$PROJECT; svn update"
# modify login defaults (e.g. uid_min/max)
/etc/login.defs
# add user
useradd <username>
# add group
usermod -a -G <groupname> <username>
# sudo info
http://askubuntu.com/questions/376199/sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used
# group info
getent group <username>
groups <username>
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Grep tool
---------------
# recursive grep
grep -r "texthere" .
# grep with filename printed on matches
grep JAVA $(find <dir> -name *.sh)
grep -r --include "*.txt" texthere .
# grep lines before after context (before, after, context=B and A)(-B,-A,-C)
grep -C 2 foo README.txt
# add color
grep --color=auto
grep --color=auto -C 3 -R -iE "exception" /var/log/storm
# only match, translate and delete chars, awk on ":" separator, print 2nd item, numeric sort
grep -o \"rank.* /tmp/ranks.txt | tr -d '"}'|awk -F: '{ print $2 }'|sort -n
# text manipulation
# merge 2 files in one file side by side (-d is the delimiter)
paste -d ' ' f1.txt f2.txt
# function stuff
which [func name]
type [func|var]
whereis [file]
# soft link
ln -s <target> <linkname>
# view real target
readlink -f .
# network - check all running ports
netstat -anp
netstat -anp|grep 9083
# network - check NIC log messages
dmesg
# dns checking
# DNS configuration
scutil --dns
# centos 7
# ifconfig and netstat are deprecated now - use ip and ss
# https://tty1.net/blog/2010/ifconfig-ip-comparison_en.html
ip addr show
ip link show
ss -a
# check connection to host/port TCP/UDP, etc.
nc -vz somedomain.com 9083
# display hostname
hostname
# install
yum groupinstall base
# list installed
yum list installed
# search packages
yum search java | grep 'java-'
#system calls
strace <command>
kerberos
--------------------
# principal makeup
[n:string](regexp)s/pattern/replacement/g
primary/instance@REALM
$1 - primary - username or host
$2 - instance - qualifies primary
$0 - realm - kerberos realm
////////////
principal = falcon/someinstance@SOMEREALM.COM
rule = RULE:[2:$1@$0](falcon@SOMEREALM.COM)s/.*/falcon/
2 components besides realm:
$1 is the username, “falcon”
$2 is the host, "someinstance"
$0 is the realm, “SOMEREALM.COM”
# default principles after db creation
# kadmin.local -q "listprincs"
Authenticating as principal root/admin@EXAMPLE.COM with password.
K/M@EXAMPLE.COM
kadmin/admin@EXAMPLE.COM
kadmin/changepw@EXAMPLE.COM
kadmin/node1@EXAMPLE.COM
krbtgt/EXAMPLE.COM@EXAMPLE.COM
# Kerberos admin options
# get principal information
kadmin.local -q "getprinc metron"
# list all principals
kadmin.local -q "listprincs"
# destroy database if having issues with commands
rm /var/kerberos/krb5kdc/principal*
the regexp turns the principal into “falcon@HWQE.HORTONWORKS.COM”
the search/replace pattern then turns the entire match into “falcon”
////////////
kadmin root/admin@SOMEDOMAIN.com -w "$passwd" -q "$query"
kinit principal -k -t keytab
kinit hdfs-primary@SOMEDOMAIN.COM -k -t /etc/security/keytabs/hdfs.headless.keytab
kinit ambari-qa-primary@SOMEDOMAIN.COM -k -t /etc/security/keytabs/smokeuser.headless.keytab
klist –k -t /etc/security/nn.service.keytab
beeline> !connect jdbc:hive2://somehost.com:10000/;principal=hive/somehost.com@SOMEDOMAIN.COM
# check kerberos rule translation
hadoop org.apache.hadoop.security.HadoopKerberosName falcon/somehost@SOMEDOMAIN.COM
echo kinit $(klist -kt /etc/security/keytabs/hdfs.headless.keytab |awk 'END{ print $4 }') -kt /etc/security/keytabs/hdfs.headless.keytab > kt.sh && chmod 755 kt.sh
# kinit with specified kdc
kinit --kdc-hostname=ec2-54-200-248-59.us-west-2.compute.amazonaws.com -kt ./metron.headless.keytab metron@EXAMPLE.COM
#encrypt files
gpg -c <filename>
> enter pass
> repeat pass
#decrypt file
gpg filename
> enter pass
FIND
--------------------
find . -not -ipath "*.git*" -not -ipath "*target*"
find . -name \*.java -o -name \*.xml \! -path \*target\* |xargs grep jobPriority
# find files modified today
find <path> -daystart -ctime 0 -print
# with exec, need space at the end before the "\;"
find /some/folder -name blah -exec cp {} newlocation/ \;
# pass multiple matches all at once to the command
find . -name pom.xml -exec grep maven-shade {} +
--------------------
MacOSX
--------------------
Shift-Command-G - Goto folder shortcut
Alt-Command-u - view source in Chrome
# IntelliJ IDEA 15
# location for maven archetypes
~/Library/Caches/IdeaIC15/Maven/Indices/UserArchetypes.xml
# shortcuts
# organize imports
ctrl-alt-o
# extract method
command-alt-m
# show type hierarchy
ctrl-h
# show methods popup
command-F12
--------------------
VSCode
--------------------
# glob search
./src/app/**/*.ts
--------------------
vim
--------------------
http://vim.wikia.com/wiki/All_the_right_moves
H move to top of screen
M move to middle of screen
L move to bottom of screen
# join all lines in file without spaces(exclamation)
%j!
# very magic mode
:help /\v
# operate on ranges of lines by pattern
34,46g/(/+, /)/ d
# put multiple values in register
:g/:/norm f:"Aye
# list all ex commands
:help holy-grail
# global with start/end patterns
g/<<</+1,/>>>/-1 s/^/##/
# substitute odd lines
3,32g/^/if line('.')%2| s/^/echo /
# sort unique
:sort u
# sort numeric/number
:sort -n
# sort range unique
:5,34sort u
# delete line after and including emtpy line
:g/^$/ .,+1d
# search and replace example - match things like "hello_this_is_me" and replace as "prefix::hello_this_is_me,"
:s/\v([_a-z]+),/prefix::\1,/
# unicode
CTRL+Vu and then the code-point number as a 4-digit hexadecimal number (pad with zeros if necessary)
# search inverse/invert and delete
:g!/pattern/d
:v/pattern/d
# show special chars, whitespace
:set list
# more whitespace color encoding
:syntax on
:set syntax=whitespace
#use yanked text in search/replace (0 represents the default buffer)
ctrl-r + 0
# Registers in Vim let you run actions or commands on text stored within them. To access a register, you type "a before a command, where a is the name of a register. If you want to copy the current line into register k, you can type
"kyy
# Or you can append to a register by using a capital letter
"Kyy
# You can then move through the document and paste it elsewhere using
"kp
# To paste from system clipboard on Linux
"+p
# To paste from system clipboard on Windows (or from "mouse highlight" clipboard on Linux)
"*p
# To access all currently defined registers type
:reg
#printing line numbers
:%s/\v(')([^,)])/\="'" . line(".") . submatch(2)/g
#increment line numbers
:let i=10 | g//let i=i+1 | s/\d/\=i."HELLO"/
or
let i=1 | g/.*/s/^/\=i.". "/ | let i=i+1
# add incremented number every third line
let i=0 | 3,37g/^/if line('.')%3 == 0 | let i=i+1| s/^/\=i.". "/
# add count i in new line before each line containing SELECT
let i=0 | g/SELECT/ | let i=i+1 | s/^/\=i."\r"/
#scrolling current line to top/bottom
zt
zb
# retabs current file
:retab
# print matches
:g/regex/p (this is what 'grep' was named after! :)
# hex editing(first enters hex, 2nd goes back to normal)
:%!xxd
:%!xxd -r
# indenting
# indent lines 4 to 8, inclusive, by one tabstop
:4,8>
less
-----
# save current less buffer contents to file
type 's' and then enter the file name and hit enter
http://www.robmeerman.co.uk/unix/256colours
export TERM=xterm-256color