Shell Script

MySQL Quick Backup

  • View
  • Edit
  • Delete
Situation: 
this function creates a demoDB.sql file of demoDB Database. The path may change according to your setup.


function dump_db {
/usr/local/mysql/bin/mysqldump -u root -p $1 > $1.sql
}


Browse thru bash_history

  • View
  • Edit
  • Delete
Situation: 
This script just browses through the .bash_history file. It displays the commands that match the keyword you type as argument.


function browse_history {
cat ~/.bash_history | grep $1
}


Add Hosts entry and apache vhost

  • View
  • Edit
  • Delete
Situation: 
Working with drupal locally might be a little bit annoying with the domain issues it can have. thats why a good option ( working with multiple installations ) is to create different host entries and create a vhost for each entry.


#Register a host in /etc/hosts
function register_host {
echo "127.0.0.1 $1.site" | sudo tee -a /etc/hosts
add_vhost $1 $2 $3 | sudo tee -a /etc/apache2/extra/httpd-vhosts.conf
sudo apachectl restart
}


function add_vhost {
echo "
#$3
<VirtualHost *:80>
ServerName $1.site
DocumentRoot /Users/webalab/$2
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log common"
</VirtualHost>"
}

Usage:


Powered by Drupal, an open source content management system