mercredi 20 août 2014

MySQL Commands

1: Login

$ mysql -u user_name -p
Enter password:

2: Create a database

mysql> create database db_name;
Query OK, 1 row affected (0.00 sec)


3: Create a user

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

4: Grant the privileges to a user

GRANT ALL PRIVILEGES ON db_name . * TO 'newuser'@'localhost';
 
Here is a short list of other common possible permissions that users can enjoy.
  • ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
  • CREATE- allows them to create new tables or databases
  • DROP- allows them to them to delete tables or databases
  • DELETE- allows them to delete rows from tables
  • INSERT- allows them to insert rows into tables
  • SELECT- allows them to use the Select command to read through databases
  • UPDATE- allow them to update table rows
  • GRANT OPTION- allows them to grant or remove other users' privileges

5: Reload privileges (e.g., once you have finalized the permissions that you want to set up for your new users)

FLUSH PRIVILEGES;
 
6: Revoke a permission

REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;

7: Delete a user

DROP USER ‘demo’@‘localhost’;

8: Delete a database

DROP DATABASE ‘demo’@‘localhost’;


END

lundi 18 août 2014

Websvn

1: download Websvn

2: unpackage websvn and move it to the apache Web root folder, rename it to svn (e.g., /var/www/svn). Here, please remove the version number (after you unpackage it, you will get something like websvn3.2.6).

3: copy the configuration file

    $cd /var/www/websvn/include
    $sudo cp distconfig.php config.php

4: open and edit the config.php.

find the following lines:

    $config->addTemplatePath($locwebsvnreal.'/templates/calm/');     $config->addTemplatePath($locwebsvnreal.'/templates/BlueGrey/');     $config->addTemplatePath($locwebsvnreal.'/templates/Elegant/'); 














and add the following line to indicate the default template to use:

    $config->setTemplatePath($locwebsvnreal.'/templates/calm/');

5: add the following lines just before the last lines: (the objective is to tell websvn where to get the data of svn)

    $config->parentPath("/media/datadrive/svn");     //you can have a parent path,     //or add another entry by using the following line:     //$config->addRepository("Empty Nest", "file:///media/datadrive/svn/emptynest");     $config->setEnscriptPath("/usr/bin");     $config->setSedPath("/bin");     $config->useEnscript();

6: now, when you open your browser, and go to:

    localhost/svn

you will be able to view svn directory.

7: However, everyone in the LAN can access to the content of svn by entering the above-mentioned URL address. The next step is to add authorization. First, create a pass word file.

    $touch /etc/apache2/dav_svn.passwd

Then, use the following command to create a user:

    $sudo htpasswd /etc/apache2/dav_svn.passwd user1    New password:     Re-type new password:     Adding password for user user1

8: Then, open the file etc/apache2/dav_svn.passwd, you can see some like this:

    user1:$apr1$PYPG.CQv$4AkadaxTsdfwBmrx6uVOK0

9: Of course, you can add more users by using the same command.

10: Then, open the apache configuration file:

    $sudo vim /etc/apache2/sites-enabled/000-default

then, add the following lines:

    <Location /svn>
            AuthType Basic
            AuthName "Subversion repository"
            AuthUserFile /etc/apache2/dav_svn.passwd
            Require valid-user
    </Location>






Save the file.

11: restart apache:

$sudo service apache2 restart
[sudo] password for wcg1sgh:
 * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
                                                                         [ OK ]





12: Open the browser, and enter localhost/svn, and a username and password is demanded.

Done!


vendredi 15 août 2014

vendredi 1 août 2014

Setup Environment Variables for XRDP in UBUNTU



when you use a xrdp client to remotely login to a ubuntu machine, you can find that the environment variables configured in the host machine are not what you can see in xrdp client.

for example, execute the following commands on both host Ubuntu machine and xrdp client machine, repectively.

echo $PATH
echo $JAVA_HOME

you can see that in your xrdp client machine, the second command returns a blank line, and the PATH variable is not identical to the one you can see in host Ubuntu machine.

Solution:

  1. open the xrdp file

    sudo vim /etc/xrdp/startwm.sh

    Then, you can see the last line is:

    . /etc/X11/Xsession
  2. add the environment setting to xrdp startup file

    Just before the last line, add the following line:

    . /etc/environment

    And save it. . /etc/environment document defines all customized environment variables, it content is like:

    JAVA_HOME="/usr/lib/jvm/jdk-1.8.0_11"
    JRE_HOME="/usr/lib/jvm/jdk-1.8.0_11/jre"
    CATALINA_HOME="/opt/tomcat/apache-tomcat-8.0.9"
    AXIS2_HOME="/opt/axis2/axis2-1.6.2"
    PATH="/usr/lib/jvm/jdk-1.8.0_11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

  3. Then, you can start your xrdp client to connect to this Ubuntu machine, then you will see that the PATH variable is the same as you can see in the host Ubuntu machine. However, the other variables are still not exported. To solve this problem, create another file /etc/environment.xrdp, its content is like:

    export JAVA_HOME="/usr/lib/jvm/jdk-1.8.0_11"
    export JRE_HOME="/usr/lib/jvm/jdk-1.8.0_11/jre"
    export CATALINA_HOME="/opt/tomcat/apache-tomcat-8.0.9"
    export AXIS2_HOME="/opt/axis2/axis2-1.6.2"

  4. reedit the file /etc/xrdp/startwm.sh, add the following line before the last line:

    . /etc/environment.xrdp

    save it.
  5. Run the xrdp client again, and you will see all the variables have been successfully imported.
Problem:

The cause of this problem is that, when you login remotely to a Ubuntu server, the server will load automatically to ~/.profile or ~/.bashrc for the configuration of your environment. If some variables are commonly used by all the users, you can use the above mentioned solution to solve the problem. Otherwise, each user can also customize his/her own environment variable in ~/.profile or ~./bashrc file.

mardi 29 juillet 2014

Add files to SVN recursively via command line

Search files in subdirectories and add them to SVN recursively
svn status | grep "^\?" | awk '{print $2}' | xargs svn add

original link: http://abhishek.nagar.me/blogs/add-files-svn-recursively-command-line

lundi 28 juillet 2014

Ubuntu change the root password of MySQL

Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.
  1. Stop the MySQL Server.
    sudo /etc/init.d/mysql stop

  2. Start the mysqld configuration.
    sudo mysqld --skip-grant-tables &

  3. Login to MySQL as root.
    mysql -u root mysql

  4. Replace YOURNEWPASSWORD with your new password!
    UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
Note: This method is not regarded as the securest way of resetting the password. However it works.

original link: http://ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password/

jeudi 24 juillet 2014

create a script that can be executed at boot in Ubuntu.

Step 1 – Create your script.
Simply create a new file (I called mine svnserve) and type the command you’d like to run
cd /etc/init.d/ # (thanks Alfonso)
sudo touch svnserve
sudo vi svnserve
svnserve -d -r /usr/local/svn/repository_name

Step 2 – Save the script in the /etc/init.d/ folder
Step 3 – Make the script executable
sudo chmod +x svnserve
Step 4 – Add the script to the boot sequence
sudo update-rc.d svnserve defaults
That’s it. When you’re done you should see some output similar to
Adding system startup for /etc/init.d/svnserve ...
/etc/rc0.d/K20svnserve -> ../init.d/svnserve
/etc/rc1.d/K20svnserve -> ../init.d/svnserve
/etc/rc6.d/K20svnserve -> ../init.d/svnserve
/etc/rc2.d/S20svnserve -> ../init.d/svnserve
/etc/rc3.d/S20svnserve -> ../init.d/svnserve
/etc/rc4.d/S20svnserve -> ../init.d/svnserve
/etc/rc5.d/S20svnserve -> ../init.d/svnserve