Tag: awk
mysql database dump restore – awk script create one script per table
mysql database dump restore – awk script create one script per table
I have used the following scripts to take a huge mysql dump scripts, with multiple databases and multiple tables, and use it to create one single script file for creating each table and for inserting the records into that table.
This script allows one to create a single large dump file for all databases on a server, yet when it comes time that some incremental restore is needed, the large dump file can be quickly stripped into files that can be used to restore a smaller incremental change.
Current Database: `49erstrivia` awk 'BEGIN{ TABLE="table_not_set"} { if($1=="--" && /Current Database:/) { CURRENTDB=$NF; gsub("`","",CURRENTDB); inserted=false; print CURRENTDB; } if($1=="CREATE" && $2=="TABLE") { TABLE=$3 gsub("`","",TABLE) inserted=false } if($1!="INSERT") { if(!inserted) { print $0 > "mysql."CURRENTDB"."TABLE".beforeinsert"; } else { print $0 > "mysql."CURRENTDB"."TABLE".afterinsert"; } } else { print $0 > "mysql."CURRENTDB"."TABLE".insert"; inserted=true } } '
AWK script to show number of apache hits per minute
AWK script to show number of apache hits per minute
Documenting this script, to save me the time of rewriting it time and again on different servers
tail -n100000 www.access.log|awk '/09/Apr/{print $4}'|awk -F'[' '{print $2}'|awk -F':' '{print $1":"$2":"$3}' |sort -n|uniq -c
This shows output like this
21 09/Apr/2015:12:48 21 09/Apr/2015:12:49 21 09/Apr/2015:12:50 21 09/Apr/2015:12:51 21 09/Apr/2015:12:52 711 09/Apr/2015:12:53 1371 09/Apr/2015:12:54 1903 09/Apr/2015:12:55 2082 09/Apr/2015:12:56 2256 09/Apr/2015:12:57 2123 09/Apr/2015:12:58 1951 09/Apr/2015:12:59 1589 09/Apr/2015:13:00 1427 09/Apr/2015:13:01 811 09/Apr/2015:13:02
awk Command to remove Non IP entries from /etc/hosts and /etc/hosts.deny
awk Command to remove Non IP entries from /etc/hosts and /etc/hosts.deny
We had a script automatically adding malicious IPS to our /etc/hosts.deny file on one of our servers.
The script went awry and ended up putting hundreds of thousands of non ip addresses into the file. There were malicious IP addresses mixed in
I used this awk script to clean it up , and remove all of the non ip addresses, and make the list unique.
awk '/ALL/ && $NF ~ /[0-9.]/' /etc/hosts.deny| sort -n -k2 |uniq > /etc/hosts.deny2
once I inspected the /etc/hosts.deny2 I replaced the original
mv /etc/hosts.deny2 /etc/hosts.deny