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/

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


echo "Nightly Backup Successful: $(date)" 
 
DISPLAY=":0" /opt/teamviewer11/teamviewer 
 
# 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

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
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 {} \;


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

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/

#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

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


# bandwidth test
iperf -s
iperf -c 192.168.10.2 
 
 
# mount image with lvm partition 
losetup /dev/loop6 Sandisk_8GB_sbc-x86_bidi.img
vgchange -an
vgchange -ay
mount /dev/mapper/Aino-root/ /mnt

vgchange -an
#untuk remove mount image
losetup -d /dev/loop6
 
 
 
#CREATE RAM DISK IN LINUX
mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk

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;


#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'@'%' ;


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)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!';
 
 

#show how many row in table 
show table status like '<TABLE NAME>' \G 
 
  
## test port
nc -z 127.0.01 22 

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

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

#apply after create partition without reboot
partprobe

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  | wc -l

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


#rsync
rsync -av rsync://repo.ukdw.ac.id/msb/14.1/1.8/x86_64/ .

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


#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 
 
 
socat -T15 udp4-recvfrom:53,reuseaddr,fork tcp:192.168.73.10:6667
socat tcp4-listen:6667,reuseaddr,fork UDP:8.8.8.8:53 
 
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 


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


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/



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