STTP

Straight To The Point

#!/usr/bin/bash
‎23 59 * * * /usr/bin2/BA
17 59 * * * /usr/bin2/BX
*/15 5-21         * * *   root    killall python2

# Execute everyday at 3 o'clock 0 minutes
0 3 * * *       root    / /home/data/app/backupdb/backup.sh 

# Execute everyday at 3 o'clock and every minutes until 3.59
* 3 * * *       root    / /home/data/app/backupdb/backup.sh 


awk "/$(date +%y\/%m\/%d)/,0"

# mencari nilai baris pada string 'smart_card' pada file alldb.sql
awk '/USE `smart_card`/{ print NR; exit }' alldb.sql


cat file.mkv.* > file.avi

chattr +i /etc/resolv.conf

cdrecord -scanbus
cdrecord -checkdrive

#Change selinux Contex version 1 
chcon -R -t mysqld_db_t /data/mysql

#Change selinux Contex version 2
chcon -R -u system_u -r object_r -t mysqld_db_t /var/lib/mysql


chmod ug+rwX /home/abimayu
setfacl -d -m g::rwx /home/abimayu/
atau
chmod g+s /home/abimayu/

# GET IP ADDRESS COMMNAND LINE 
curl http://icanhazip.com 


dd if=/dev/zero of=/dev/sdb
dd if=/home/iso/slackware-14.0-install-dvd.iso of=/dev/sdb
dd if=/dev/sdb of=/dev/sdc bs=32M

# delete mbr including all partitions 
dd if=/dev/zero of=/dev/sdc bs=512 count=1
 
# delete mbr including all partitions 
dd if=/dev/zero of=/dev/sdc bs=446 count=1



# ======== DOCKER ============ 
#build
docker build -t pgadmin429 .

#check run docker
docker ps

#image list
docker image ls
docker image ls -a

#container list
docker container ls -a

#run
docker run -d  -e 'PGADMIN_DEFAULT_EMAIL=root@abimayu.com' -e 'PGADMIN_DEFAULT_PASSWORD=password' --name pgadmin429 pgadmin429 -p 8081:80
docker run -d -p 80:8080  --name phpldapadmin phpldapadmin-alpine-httpd

#check ip 
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pgadmin429

#start
docker start phpldapadmin


#kill docker
docker rm $(docker ps -a -q -f name=service-app) -f

echo "Nightly Backup Successful: $(date)"

DISPLAY=":0" /opt/teamviewer11/teamviewer 

# check disk looping 
for d in ./*/ ; do (du -h  "$d" | tail -n 1 ); done 


# check speed NIC
ethtool eth0


## proxy from command line
export http_proxy=http://user:password@192.168.0.200:3128

mencoder -forceidx -oac copy -ovc copy file.avi -o file_final.avi

fbsetbg wallpaper.png

ffmpeg -i file.mp4 -f mp3 -ab 192000 file.mp3
ffmpeg -i file.mp4 -vn -ar 44100 -ac 2 -ab 192k -f mp3 file.mp3

#find duplicate files same size
for FILE in *; do stat -c"%s/%n" "$FILE"; done | awk -F/ '{if ($1 in a)print $2; else a[$1]=1}'


#find duplicate files
find . -type f -printf "%p - %s\n" | sort -nr -k3 | uniq -D -f1 | more


# == Multiple command ==
find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \;
 

## count how many found file
find * /home/test | wc -l

## remove file older 30days ##
find /cf-rw2/data/ -mtime +30 -exec rm -f {} \;
find . -type f -iname '*.txt' -exec mv {} ./test/ \;
find . -type f -iname '*.cpp' -exec dos2unix {} \;

## find .com 
grep -h -R '\.com' . 

## CONVERT FROM DOS FORMAT TO UNIX
find . -exec dos2unix {} \;

# FIREWALLD ADD
iptables-save > name-files.rules
firewall-cmd --list-all-zones
firewall-cmd --permanent --add-forward-port="port=29810:proto=tcp:toport=8080:toaddr=172.30.30.182" --zone=trusted
firewall-cmd --reload


# FIREWALLD REMOVE
iptables-save > name-files.rules 
firewall-cmd --list-all-zones

firewall-cmd --permanent --remove-forward-port="port=29810:proto=tcp:toport=8080:toaddr=172.30.30.182" --zone=trusted
firewall-cmd --reload

sed 's/\r$//' < input.txt > output.txt

#parsing hanya baris 2 dari fileee
sed '2!d' fileee  > hasil.txt

#parsing hanya baris 2 s/d 5 dari fileee
sed '2,5!d' fileee  > hasil.txt

#parsing kecuali baris 2 s/d 5 dari fileee ( file original masih ada )
sed '2,5d' fileee  > hasil.txt

#menghapus hanya baris 2 s/d 5 dari fileee ( pada file original )
sed -i '2,5d' fileee


# Check RAM
free -m

cat /proc/cpuinfo


# Find word in file
grep --color -R 'kata' /opt/

# Grep multiple word
grep 'word1\|word2\|word3'


# Parse comment "#"
egrep -v "^$|^[[:space:]]*#" /etc/postfix/main.cf

# Check url repo from current directory
git config --get remote.origin.url# Check url repo last commit from current directory
git log --name-status HEAD^..HEAD


#redirect from it self
iptables -t nat -D PREROUTING -p tcp --dport 80 -d 192.168.18.253 -j REDIRECT --to-port 8080

ip addr add 192.168.111.12/24 dev eth0:0

ip route 192.168.244.247 via 192.168.254.74

ifconfig eth0|grep "inet addr"|cut -d : -f 2 |cut -d " " -f 1


# sync email
imapsync --host1 imap.googlemail.com --user1 namauser1@abimayu.com --password1 indonesia --host2 103.4.52.94 --user2 namauser2@gmail.com --password2 rahasia --noauthmd5 -ssl1 -ssl2


# check io process PID 
iotop -b | grep cloud 


# bandwidth test
iperf -s
iperf -c 192.168.10.2

# Running log write stdout java 
java -jar engine.jar config.properties download -d > running.log 2>&1 

# mount image with lvm partition 
losetup -f -P ImageVM_SBC_Sandisk_4GB_.img
vgchange -an
vgchange -ay
mount /dev/mapper/Aino-root/ /mnt

vgchange -an
#untuk remove mount image
losetup -d /dev/loop6

# untuk mengecek proses rsync
lsof -ad3-999 -c rsync 


=== ( MEGARAID SECTION ) ===
# Check patrol read warnings:
MegaCli -ShowSummary -aALL

# View information about physical drives
MegaCli -PDList -aALL

# View information about virtual disks Useful for checking RAID level, stripe size, cache policy and RAID state
MegaCli -LDInfo -Lall -aALL

# To see information about the patrol read state and the delay between patrol read runs
MegaCli -AdpPR -Info -aALL

# Super detail info all adaptor
MegaCli -AdpAllInfo -aAll




#CREATE RAM DISK IN LINUX
mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk


# ====== MYSQL ====== 
mysqladmin -u root -p'paswod'

mysql> GRANT ALL ON `demo`.* TO user@localhost IDENTIFIED BY 'mypass';
mysql> GRANT ALL PRIVILEGES ON `demo`.* TO 'user'@'%' IDENTIFIED BY 'mypass';
or
mysql> GRANT SELECT ON `demo`.* TO 'user'@'%' IDENTIFIED BY 'mypass';
mysql> FLUSH PRIVILEGES;

# show processlist 
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST 

#check mysql user
mysql>  select user,host from mysql.user;
mysql>  show grants for 'user'@'host';
mysql>  revoke all privileges on *.* from 'user'@'host';
mysql>  grant SELECT,INSERT,UPDATE,DELETE ON `db`.* TO 'user'@'host';
mysql>  flush privileges;


# == SPESIFIC USER AKSES INSERT , SELECT , UPDATE ==
GRANT INSERT, SELECT, UPDATE ON demo.* TO 'user'@'%' ;


# DUMP
mysqldump -d -u username_user -p username_dbname > file.sql
mysqldump -u username dbname -t table --where="fiedlDate BETWEEN '2013-01-01' AND '2013-01-30'" -p > dump-januari.sql
mysqldump -u root -p --all-databases --ignore-database=performance_schema --ignore-database=information_schema


mysql> ALTER TABLE track_raw ADD trackTimestamp datetime AFTER trackRawData;
mysql> CREATE UNIQUE INDEX trackRawUnique ON track_raw(trackRawBusCode,trackTimestamp);
mysql> ALTER TABLE track_raw DROP trackTimestamp;


mysql> SET FOREIGN_KEY_CHECKS = 0; 
mysql> TRUNCATE table1; 
mysql> SET FOREIGN_KEY_CHECKS = 1; 

# == RESTORE MySQL ==
mysql> use db_name;
mysql> SET autocommit=0 ; source the_sql_file.sql ; COMMIT ;


# == Start MySQL 5.7 ==
shell> sudo grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p (input password from result above)
shell> mysql -uroot -p (input password from result above)


# == COUNT TABLE RAW [MySQL] ==
select * from information_schema.TABLES where table_name = 'table_name'\G 



# == mount spesifik ==
ntfs-3g -o umask=1000,gid=1000,uid=33 /dev/sdb1 /mnt/hd/



# Create password 
python3 -c "from getpass import getpass; from crypt import *; p=getpass(); print('\n'+crypt(p, METHOD_SHA512)) if p==getpass('Please repeat: ') else print('\nFailed repeating.')" 


# foreign key ( antar tabel )
SET foreign_key_checks = 0;
SET foreign_key_checks = 1;  


#show how many row in table 
show table status like '[TABLE NAME]' \G
  

# build package slackware
make
make install DESTDIR={Name Directory}
cd {Name Directory}
/sbin/makepkg -l y -c n /dev/shm/{Name App}-x86_64.txz 


 
## test port
nc -z 127.0.01 22 

## check port
nc -z -w5 demo.ainosi.co.id 80 ;echo $?
--> 0 = success
--> 1 = failed

# test port spesific source address 
nc -s 192.168.55.21 -zv 10.142.0.2 80 


netstat -natuop  (servers and established)
netstat -nptl    (only servers)


# Check port 
(echo >/dev/tcp/google.com/80) &>/dev/null && echo "TCP port 80 open" || echo "TCP port 80 close" 

# Check ssl file 
openssl x509 -in /etc/ssl/certs/selfsigned.crt -text -noout


# ==== remote oc client =====
oc new-app openshiftkatacoda/blog-django-py --name blog 

oc get pods 
oc get svc #get okd resource used
oc describe node node-a01.abimayu.com --show-events=false

# tunnel OKD
oc port-forward pg-abimayu-7-hmcv8 1234:5432

# copy file
oc rsync [container/pod]:/var/lib/pgsql/request_query   [lokasi dir di laptop kita]# run as root
oc debug --as-root abimayu-report-api

#Remove namespace with force
oc delete project abimayu-ganteng --force --grace-period=0

# build apps
oc start-build appsName --follow --loglevel=8 --build-loglevel=8 -F


# Check glasterfs
# --------------------------
oc project app-storage
oc get pods | grep heketi
oc rsh heketi-storage-1-65ncq bash

heketi-cli cluster list
heketi-cli cluster info 0dddf2623f159606f94edcaad3a67b91
heketi-cli node info 1dd62ca43df1fc91e4456882725e0bd4
heketi-cli node info 2aa46426aba64f21041d37c6190d47b8
heketi-cli node info a8e07e7ea84d5a79936eb0ebf30e8645

#apply after create partition without reboot
partprobe

#split pdf 
pdftk NewStructure2019.pdf cat 2-3 output NewStructure2019-2-3.pdf 

picocom /dev/ttyUSB2
at+csq
CTRL+A
CTRL+X

ps ax | grep python | grep -v grep
pgrep -f keyword

#CHECK AGE PROSES | HOW LONG 
ps -eo uid,pid,etime | grep $(pgrep -f nama_proses)

#CHECK how much thread
ps huH p [pid_of_u_process] | wc -l


===== POSTGRESSQL =====
# show all process running 
select * from pg_stat_activity;

# show all process running with file
psql -h localhost -U postgres  -c "select * from pg_stat_activity;" > /dev/shm/show_process_list.txt

# show connection use by user in POSTGRES
select pid as process_id, usename as username, datname as database_name, client_addr as client_address, application_name, backend_start,state, state_change from pg_stat_activity;

# show connection use by user in POSTGRES filter by last lang connection
select pid as process_id, usename as username, datname as database_name, client_addr as client_address, application_name, backend_start,state, state_change from pg_stat_activity where usename='nama user' and (now() - pg_stat_activity.query_start) > interval '40 minutes';

# show max connection each user
SELECT rolname, rolconnlimit FROM pg_roles WHERE rolconnlimit <> -1;

# kill spesic proses user
SELECT pg_terminate_backend(pid) FROM pg_stat_activity where usename='nama user' and (now() - pg_stat_activity.query_start) > interval '60 minutes';

# show all schema
\dn

# show what schema using right now
SHOW search_path; 

# set to access schema
SET search_path TO [nama shecma];

# dump all
pg_dumpall -U postgres > pgbackup_all.sql

# Dump a PostgreSQL table as insert statements
pg_dump -h localhost -p 5432 -U user -W  --table="table-name" --data-only --column-inserts database-name > table.sql
# restore
psql -h localhost -p 5432 -U user database-name -f table.sql


# dump spesifict database
DUMP pg_dump -U postgres -W -F t [database] > [database].tar

# dump all schema
pg_dumpall --schema-only > all_schema.sql

# dump rule only
pg_dumpall --roles-only > allroles.sql

# dump table space only
pg_dumpall --tablespaces-only > table_space.sql

# dump all with compression
pg_dumpall -U postgres | gzip -c > pgbackup_db_name.gz


#LVM
pvdisplay -C --units M
lvresize -L +100G Arch/data
e2fsck -f /dev/Arch/data
esize2fs -p /dev/Arch/data

#route at MacOS
route -n get 192.168.123.1
sudo route delete 192.168.123.1
sudo route -n add -net 192.168.123.1 10.11.0.1 
#rsync
rsync -av rsync://repo.ukdw.ac.id/msb/14.1/1.8/x86_64/ .

#for duplicate folder 1 machine
rsync -rtv source/ destination/

rsync -av -e 'ssh -p8380' /var/lib/mysql/ root@172.16.24.13:/var/lib/mysql/

rsync -avhPHAXx -e 'ssh -p8380' root@172.16.24.13:/var/lib/mysql/ /var/lib/mysql/


# pengganti scp to continues
rsync -P -e "ssh -p5902" abim@server.abimayu.com:/home/abim/file.iso . 

#SALT REMOTE MASS
salt 'kor55_halte88' cmd.run 'ssh -p8382 -fN -R 22004:localhost:22 ungu@123.123.123.123'

sdiff file1.txt file2.txt

## read line 120 145 1050
sed -n -e 120p -e 145p -e 1050p /var/log/syslog


## remote sftp
sftp -oPort=3476 user@host
sftp -oPort=3476 -oIdentityFile=file_key.ppk user@host
socat -T15 udp4-recvfrom:53,reuseaddr,fork tcp:192.168.73.10:6667
socat tcp4-listen:6667,reuseaddr,fork UDP:8.8.8.8:5
sshpass -p '123' ssh -p 9002 -o StrictHostKeyChecking=no admin@192.168.1.1 "/ip address print"

ssh -p 9001 -R 22002:localhost:22 admin@123.123.123.132
ssh -l admin localhost -p 22002

ssh -v 192.168.1.1

ssh-keygen
ssh-copy-id -i .ssh/id_rsa.pub user@192.168.254.93
ssh user@192.168.254.93

ssh-keygen -t rsa
scp /root/.ssh/id_rsa.pub user@host-target:/home/user
@host-target #cat id_rsa.pub >> .ssh/authorized_keys
@host-target #chmod 700 .ssh
@host-target #chmod 640 .ssh/authorized_keys


#Tunnel
ssh -p8382 -L 80:abimayu.com:2082 abi@123.123.123.123 -N
ssh -p8382 -D 192.168.1.7:81 smts@123.123.123.123



# Sniffing network
tcpdump -i eth0 'port 80' and dst host 103.31.250.43 and src host 114.127.245.15
tcpdump -i eth0 'port 80' and dst host 103.31.250.43



## knowing  how long
time ping yahoo.com


traceroute -T -p 80 www.abimayu.com


## Check batere
upower -d
upower -i /org/freedesktop/UPower/devices/battery_BAT0


# keyboard keyrepeat
xset r rate 300 32 


# centos install default
yum install php-gd php-common php-cli php-xml php-mysql php-intl php-pdo php htop mc telnet sshfs nano



## GZIP
gunzip file.gz
gzip -d file.gz


TAR
# tar -cvf archive_name.tar directory_to_compress
# tar -xvf archive_name.tar.gz

#TAR.GZ
tar -zcvf archive_name.tar.gz directory_to_compress
tar -zxvf archive_name.tar.gz

# when extract skip folder ( just contain in directory )
tar xf archive.tar -C /target/directory --strip-components=1

TAR.BZ2
tar -jcvf archive_name.tar.bz2 directory_to_compress
tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

#WITH spesific core processor 
export XZ_DEFAULTS="-T 5" && tar -Jcf dbbackup_all.txz dbbackup_all.sql

#Mirror Display
xrandr --query
xrandr --output HDMI-0 --mode 1366x768 --output HDMI-0 --right-of VGA-0 --mode 1920x1080 --scale 0.711x0.711 

#ZIP
zip -r archive_name.zip directory_to_compress
unzip archive_name.zip

#COUNT WORD IN LINE
tr -s ' ' '\n' < /cf-rw1/data/log/2013-11-21 | grep -c 'readCardVersion'


usermod -a -G ftp abimayu
chmod ug+rwX /home/abimayu/inbox
setfacl -d -m g::rwx /home/abimayu/


.mc/ini
[Colors]
base_color=lightgray,green:normal=white,default:selected=white,white:marked=yellow,default:markselect=yellow,gray:directory=blue,default:executable=brightgreen,default:link=cyan,default:device=brightmagenta,default:special=lightgray,default:errors=red,default:reverse=red,default:gauge=red,white:input=white,gray:dnormal=red,gray:dfocus=brightred,gray:dhotnormal=cyan,gray:dhotfocus=brightcyan,gray:menu=red,default:menuhot=cyan,default:menusel=red,gray:menuhotsel=cyan,default:helpnormal=cyan,default:editnormal=green,default:editbold=blue,default:editmarked=gray,blue:stalelink=red,default


netsh wlan stop hostednetwork
netsh wlan set hostednetwork mode=allow ssid=denWifi key=12345678
netsh wlan start hostednetwork
div>