Linux

Backup mysql databases into separate files

This bach script makes separate backup files of all the databases in mysql and saves the result in the mysql_backup folder. #!/bin/bash -v USERNAME=’yourusername’ PASSWORD=’yourpassword’ HOSTNAME=’yourhostname’ BackupFolder=’/backup’ for i in $(echo ‘SHOW DATABASES;’ | mysql –user $USERNAME -p$PASSWORD -h $HOSTNAME | grep -v ‘^Database$’ ); do mysqldump –user $USERNAME -p$PASSWORD -h $HOSTNAME –opt $i > […]

Read More
Scripting

Strip EXIF tags from JPG files

Sometimes it’s a good idea to remove the hidden data a JPG file contains, like when you publish picures on the Internet. An easy way to remove all EXIF-tags from your JPG files is to run the command using jhead jhead -purejpg *.jpg

Read More
Scripting

Sort IP address

Sorting IP addresses using sort is not easy because the dot confuses sort. This line makes it possible to sort by the whole value of the address sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 ipaddresses.txt You can also sort by the last octet sort -r. -n +3.0 ipaddresses.txt

Read More
Scripting

Grep recursively through subdirectories

grep recursively through subdirectories for files that match a specific pattern: grep -l -r –include=*.doc regex * The equivalent command unsing find: find . -name ‘*.doc’ -exec grep -l regex \{\} \; The option after grep is the lowercase letter L, not the number 1). Remove the -l to see the actual matches instead of […]

Read More