Gnu/Linux commands for every day

Some general Linux related apps commands for easy remember

MySQL

Check and repair Mysql databases and tables

mysqlcheck -A -p --auto-repair

#in /var/lib/mysql/<database>

myisamchk -r -f cdr.MYI

Optimize tables after delete large number of records to save space in disk

mysql> use asteriskcdrdb;

mysql> OPTIMIZE TABLE cdr;

Users and privileges

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

From specific IP and database

mysql> GRANT ALL PRIVILEGES ON databasename.* TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

NETWORKING

Scan devices on network by network interface

arp-scan --interface=wlan0 --localnet
arp-scan --interface=wlan0 10.0.1.0/24

Add static route to network

route add -net 10.11.0.0/16 gw 10.11.220.29 eth1

Find Ip public address

dig +short myip.opendns.com @resolver1.opendns.com

or

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'

FILE SYSTEM | FreePBX

view all:-
find /var/spool/asterisk/monitor/* -name “*.wav”
to delete older than 30 days:-
find /var/spool/asterisk/monitor/* -name “*.wav” -mtime 30 -delete
Move to another location
find /var/spool/asterisk/monitor/ -name "*-2015*" -maxdepth 1 -exec sh -c 'mv -v "$@" "$0"' /home/usb/elastix/ {} +