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.