![]() |
Simple Bash Script to grep for keywords in MySQL dump files
Greetings all,
I am looking for a simple example of a bash script to grep for keywords in MySQL dump files. The files are located in different directories is the problem. Anyone have an idea of where to get started? /path/to/parent/mysql/dump/directory /server1 /server2 /server3 etc. |
grep allows you to specify multiple files - since 3 of your directories have only one character difference you can specify it like this:
grep <keyword> /path/to/parent/mysql/dump/directory/* /server?/* That will include the file name in which it was found in the output. |
try
Code:
for KEYWORD in $*; do |
Tried this!
[QUOTE=pgpython;3560519]try
Code:
for KEYWORD in $*; doCode:
#!/bin/bashThanks a million, Newb Sys Admin |
You're misunderstanding the $KEYWORD. That is a variable set when you invoke the script.
Put the script as written into a file (e.g. grepit.sh), make the file executable (e.g. chmod 755 grepit.sh) then run the file with the keyword you want e.g. ./grepit.sh http: The file (called a script) will convert set KEYWORD variable as what you typed (httpd: ) so when it greps for $KEYWORD it will actually be grepping for "httpd:" If you later decide to look for something else it you type that. For example if you want to look for .org you'd type: ./grepit.sh .org |
You can use the > character to redirect your output:
Code:
./grepit.sh httpd .org > /var/log/mylog.logthe > character will erase the files previous contents if it exists. If you want to append to the file instead use >> |
Not sure whether you make the dump especially with the purpose to perfom a text search on it, or the dump file is just what you happen to have.
In case you make the dumpfile especially to perform a text search, why not query the database from bash? Code:
echo "SELECT urlname, morecolumns FROM tablename WHERE urlname LIKE \"%http://%\"" | /path/to/mysql -s -uusername -ppasswordjlinkels |
Quote:
/server1 /server2 /server3 are under /path/to/parent/mysql/dump/directory then using grep -r "Search_string" /path/to/parent/mysql/dump/directory should do the trick! :) Linux Archive |
| All times are GMT -5. The time now is 03:02 PM. |