Thursday, November 22, 2007
select statement to csv
INTO OUTFILE '/tmp/report.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
Tuesday, September 4, 2007
Chained Replication MySQL
To allow a slave to act as a master to another slave use the
log-slave-updates option in my.cnf, this along with the other standard settings for master-slave configuration i.e.
log-bin=YOUR_BINARY_LOG (in your master my.cnf)
Monday, September 3, 2007
Search and replace string in multiple files
Thursday, August 16, 2007
Thursday, August 9, 2007
Wednesday, August 8, 2007
Ghost your LVM to new drive
2.) Use dd to copy the data across, make sure the drives are in the correct order or you'll loose everything
prompt>: dd if=/dev/oldhda of=/dev/newhdc bs=446 count=1
prompt>: dd if=/dev/oldhda1 of=/dev/newhdc1
prompt>: dd if=/dev/oldhda... of=/dev/newhdc...
prompt>: dd if=/dev/oldhdaN of=/dev/newhdcN
Shutdown and put the new drive in the old drives place.
New drive should now boot
Wednesday, August 1, 2007
Wednesday, July 18, 2007
lower2upper convert case of filename
Using tr
mv filename `echo filename | tr '[:lower:]' '[:upper:]'`
Using sed
mv filename `echo filename | sed -e 's/[a-z]/\U&/g'`
Wednesday, June 27, 2007
Wednesday, June 20, 2007
ServerTokens Prod, ServerSignature Off
ServerSignature Off
ServerTokens Prod
While it doesn't make your server any more secure, it may make it less of a target.
Tuesday, May 22, 2007
find and print to file with modification
Thursday, May 17, 2007
Can't su to root and sure that your pam is configured properly?????
chmod u+s /bin/su
Thursday, May 10, 2007
Simple Bash For Loop
for
do
target=$(echo $file | sed -e "s/\ \ /\ /")
mv $file $target
done
Tuesday, May 8, 2007
Restoring MySQL database
Restore using mysql
If you have to re-build your database from scratch, you can easily restore the mysqldump file by using the mysql command. This method is usually used to recreate or rebuild the database from scratch.
Here's how you would restore your custback.sql file to the Customers database.
mysql -u sadmin -p pass21 Customers <>
Easy isn't it ? Here's the general format you would follow:
mysql -u [username] -p [password] [database_to_restore] < [backupfile]
Now how about those zipped files? You can restore your zipped backup files by first uncompressing its contents and then sending it to mysql.
gunzip <>
You can also combine two or more backup files to restore at the same time, using the cat command. Here's how you can do that.
cat backup1.sql backup.sql | mysql -u sadmin -p pass21
Moving Data Directly Between Databases
How would you like to replicate your present database to a new location? When you are shifting web hosts or database servers, you can directly copy data to the new database without having to create a database backup on your machine and restoring the same on the new server. mysql allows you to connect to a remote database server to run sql commands. Using this feature, we can pipe the output from mysqldump and ask mysql to connect to the remote database server to populate the new database. Let's say we want to recreate the Customers database on a new database server located at 202.32.12.32, we can run the following set of commands to replicate the present database at the new server.
mysqldump -u sadmin -p pass21 Customers | mysql --host=202.32.12.32 -C Customers
Thursday, May 3, 2007
Generate PEM certs
Generation of a "pemfile"
First generate an openssl configuration (or if you have one use it). It might look like this... it is just an example! (-:
----- BEGIN:monit.cnf -----
# create RSA certs - Server
RANDFILE = ./openssl.rnd
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
[ req_dn ]
countryName = Country Name (2 letter code)
countryName_default = MO
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = Monitoria
localityName = Locality Name (eg, city)
localityName_default = Monittown
organizationName = Organization Name (eg, company)
organizationName_default = Monit Inc.
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Dept. of Monitoring Technologies
commonName = Common Name (FQDN of your server)
commonName_default = server.monit.mo
emailAddress = Email Address
emailAddress_default = root@monit.mo
[ cert_type ]
nsCertType = server
----- END:monit.cnf -----
In order to generate the actual pemfile just run these commands:
# Generates the private key and the certificate
/usr/local/bin/openssl req -new -x509 -days 365 -nodes \
-config ./monit.cnf -out /var/certs/monit.pem \
-keyout /var/certs/monit.pem
# Generates the Diffie-Hellman Parameters
/usr/local/bin/openssl gendh 512 >> /var/certs/monit.pem
# Prints out the certificate information
/usr/local/bin/openssl x509 -subject -dates -fingerprint -noout \
-in /var/certs/monit.pem
Vi Search and replace
Advanced Search and Replace
- Use :s/foo/bar/ to replace the first occurrence of the word foo on the current line with the word bar.
- Use :s/foo/bar/g to replace all occurrences of the word foo on the current line with the word bar.
- Use :%s/foo/bar/g to replace all occurrences of the word foo in the current file with the word bar. Leaving off the g at the end only replaces the first occurrence of foo on each line of the current file.
- Use :%s/foo//g to delete all occurrences of the word foo in the current file. Leaving off the percent sign (%), of course, only does this for the current line.
- Use :%s/foo/bar/gc to have Vi query you before each attempt to replace the word foo with the word bar.
Wednesday, April 18, 2007
Find All Items In a subtree
find ./ -type d | wc -l
find files:
find ./ -type f | wc -l
Remove All Empty Directories
prompt:>> perl -MFile::Find -e"finddepth(sub{rmdir},'.')"
Its safe, rmdir won't delete a directory with anything in it