Install R CentOS 5

I have tried installing R on CentOS 5.5 by the following way and it test good.

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install R



You can run the R with scripts from cmd line by doing one of the following:

R < mean.R
R CMD BATCH mean.R
Rscript mean.R

Creating Local Git Repositories

I accidently delete all my project stuffs by rm -rf.

Yeah I should be more careful. But it happens, this is life. Well the bad thing is that that folder also serves as my git repository. So I lost all my hard work. To avoid that I deceide to set up another local folder to serve as a remote git repository. The next time I will have a working copy there. Hope....

Let us start

1. make a directory:

mkdir ~/gitrepositories/pathogenbase.git

2. enter the new create diretory and initialize the repository

cd ~/gitrepositories/pathogenbase.git

git init --bare

3. now we have a working "remote" repository. We are ready to make a local clone:

cd ~

git clone ~/gitrepositories/pathogenbase.git pathogenbase

4. now we have an empty clone, at my home directory

5. creat a file touch file1

6. git add .

7. git commit -m "create file1"

9. git push origin master

Creating Local Git Repositories

I accidently delete all my project stuffs by rm -rf.

Yeah I should be more careful. But it happens, this is life. Well the bad thing is that that folder also serves as my git repository. So I lost all my hard work. To avoid that I deceide to set up another local folder to serve as a remote git repository. The next time I will have a working copy there. Hope....

Let us start

1. make a directory:

mkdir ~/gitrepositories/pathogenbase.git

2. enter the new create diretory and initialize the repository

cd ~/gitrepositories/pathogenbase.git

git init --bare

3. now we have a working "remote" repository. We are ready to make a local clone:

cd ~

git clone ~/gitrepositories/pathogenbase.git pathogenbase

4. now we have an empty clone, at my home directory

5. creat a file touch file1

6. git add .

7. git commit -m "create file1"

9. git push origin master

Create Django Dynamic Hyper Links and get parameters from them

I was trying to use a template to create dynmic hyperlinks and get parameters from them. Searched online and found two ways to do that according to what types of the url you are creating

type 1: http://localhost:8000/pathogen/detaildemo/28

type 2: http://localhost:8000/pathogen/detaildemo/?id=28

For type 2: if you want to get the value of id, 28 in this case, you  will have to use request.GET.get('id')

in template file you have such code to create dynamic hyperlnks


                {% with table.rows as rows %}
                    {% paginate rows %}
                    {% for row in rows %}
                       
                        {% for value in row %}
                        {{ value }}
                        {% endfor %}
                       
                       
                    {% endfor %}
                    {% show_pages %}
                {% endwith %}

 

in url file you have

urlpatterns = patterns('',
   
 .......
    url(r'^detaildemo/$', views.someDemographics, name = 'show_some_demographics'),
.......

)

in view file you have

def someDemographics(request):
    isolateId = request.GET.get('id')
    initial_queryset = Demographic.objects.filter(isolate=isolateId)
    demographicTable = DemographicTable (
        initial_queryset,
        order_by=request.GET.get('sort', 'isolate')
    )
    context = {
        'table':demographicTable,
        'a_title':'Demographic',
        'b_title' : '../demographicsearch/',
       
    }
    return render_to_response(
        'pathogen/detaildemographic.html',
        context,
        context_instance=RequestContext(request),
    )

 

I am working on type 1 now.

Create Django Dynamic Hyper Links and get parameters from them

I was trying to use a template to create dynmic hyperlinks and get parameters from them. Searched online and found two ways to do that according to what types of the url you are creating

type 1: http://localhost:8000/pathogen/detaildemo/28

type 2: http://localhost:8000/pathogen/detaildemo/?id=28

For type 2: if you want to get the value of id, 28 in this case, you  will have to use request.GET.get('id')

in template file you have such code to create dynamic hyperlnks

<tbody>
                {% with table.rows as rows %}
                    {% paginate rows %}
                    {% for row in rows %}
                        <tr>
                        {% for value in row %}
                        <td > <a href={% url pathogenbase.apps.pathogen.views.someDemographics %}?id={{row.isolate }}>{{ value }}</a> </td>
                        {% endfor %}
                       
                        </tr>
                    {% endfor %}
                    {% show_pages %}
                {% endwith %}

</tbody>

 

in url file you have

urlpatterns = patterns('',
   
 .......
    url(r'^detaildemo/$', views.someDemographics, name = 'show_some_demographics'),
.......

)

in view file you have

def someDemographics(request):
    isolateId = request.GET.get('id')
    initial_queryset = Demographic.objects.filter(isolate=isolateId)
    demographicTable = DemographicTable (
        initial_queryset,
        order_by=request.GET.get('sort', 'isolate')
    )
    context = {
        'table':demographicTable,
        'a_title':'Demographic',
        'b_title' : '../demographicsearch/',
       
    }
    return render_to_response(
        'pathogen/detaildemographic.html',
        context,
        context_instance=RequestContext(request),
    )

 

I am working on type 1 now.

CSS Strikethrough

I was wondering what's the name of the cross-line in CSS file. After consulted with my coworker and knew it is strikethrough. However when I put the trikethrough in the css file it does not work.

The true name is: line-through.

To make strikethrough text using CSS, use text-decoration: line-through in your style sheet.


CSS Strikethrough

I was wondering what's the name of the cross-line in CSS file. After consulted with my coworker and knew it is strikethrough. However when I put the trikethrough in the css file it does not work.

The true name is: line-through.

To make strikethrough text using CSS, use text-decoration: line-through in your style sheet.


Switched back to Blogger

Couple months ago, I switched to WordPress because Blogger has less function I need comparing to WordPress. Today I moved back to Blogger because I want to use my own domain name with my blog and found out that WordPress charge $12/per/blog for using your own domain. That's sucks.....
I moved all of my old contents to Blogger, by doing the following steps
1. Login to your wordpress account and navigate to the Dashboard
2. From manage tab >> export >> xml file
3. Save the xml file into your local machine. At this moment if you tried to import this xml file into Blogger you will fail, because the structures of the xml files these two websites using are different
4. go to this website to format the xml file: http://wordpress2blogger.appspot.com/ and re-import to Blogger


Vim Tips

1. remove the last character, if it presents in vim: The following commandremoves the "," from the end of the line if it presents.
:%s/,$//g
2. ^M in vim
to remove the ^M use %s/+ //g
press ctrl+v key and then hit Enter key to input ^M in vim command mode.
3. Replace ^with #:
:set number
:10,12s/^/#

Finish replacing you may find that the first column of the file is still inhighlight mode, to clear:

use :noh

Vim Tips

1. remove the last character, if it presents in vim: The following command removes the "," from the end of the line if it presents.
:%s/,$//g
2. ^M in vim
to remove the ^M use %s/<ctrl+V>+ <Enter>//g
press ctrl+v key and then hit Enter key to input ^M in vim command mode.
3. Replace ^with #:
:set number
:10,12s/^/#

Finish replacing you may find that the first column of the file is still in highlight mode, to clear:

use :noh

Add printer with Tomato USB on Asus to MacOSX

Add printer >> JetDirect Printer >> put down the router's IP address and port number 9100, 192.168.1.1:9100 >> from the dropdown list to find your printer's driver

Add printer with Tomato USB on Asus to MacOSX

Add printer >> JetDirect Printer >> put down the router's IP address and port number 9100, 192.168.1.1:9100 >> from the dropdown list to find your printer's driver

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

 

 

 

 

 

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

 

 

 

 

 

Use Curl to batch download files from a website

In this example, we suppose all the files are in the same folder on the website and the file names have the same pattern:

$ curl -L -O http://www.example site.com/color/pic/fire[1-5].gif

-L : Follows all redirections until the final destination page is found. This switch is almost always required as curl won’t follow redirects by default (read about how to check the server http headers with curl).
-O : By using this switch you instruct curl to save the downloaded data to a file in the current directory. The filename of the remote file is used. This switch is also required or else curl will print the data to stdout, which is something you won’t probably like.


wget all files of the same type

To get all the pdf files:this command does not work on all websites.

$ wget -r -l1 –no-parent -A.pdf 

Use Curl to batch download files from a website

In this example, we suppose all the files are in the same folder on the website and the file names have the same pattern:

$ curl -L -O http://www.example site.com/color/pic/fire[1-5].gif

-L : Follows all redirections until the final destination page is found. This switch is almost always required as curl won’t follow redirects by default (read about how to check the server http headers with curl).
-O : By using this switch you instruct curl to save the downloaded data to a file in the current directory. The filename of the remote file is used. This switch is also required or else curl will print the data to stdout, which is something you won’t probably like.


wget all files of the same type

To get all the pdf files:this command does not work on all websites.

$ wget -r -l1 –no-parent -A.pdf  <url>

CentOS user and group, Create user and add it to the sudoers list

Create user and add to the exiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

/usr/sbin/groupadd group_name

If you do not use the group option then the user will be assigned to the group with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

usr -r option if you also want to delete the user's home folder

User and group related files:

cat /etc/passwd

cat /etc/group

Example:

Create a user and add the user to the sudoers list: Use root account to do the following steps


1. create sudoers group: /usr/sbin/groupadd sudoers


2. create user: /usr/sbin/useradd -G sudoers htang

3.  modify the /etc/sudoers file bu adding the write attribute

chmod +w /etc/sudoers

4. modify the following lines:

## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)    ALL

to

## Allows people in group wheel to run all commands
%sudoers  ALL=(ALL)    ALL

change the %wheel to %sudoers and remove the comment

5. remove the write attribute of /etc/sudoers file

chmod -w /etc/sudoers

CentOS user and user group

Create user and add to the esiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

groupadd group_name

If you do not use the group option then the user will be assigned to thegroup with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

User and group related files:

cat /etc/passwd

cat /etc/gshdow

Configuring Samba on CentOS

1 .Installing samba via yum

yum -y install samba samba-common samba-client

Configuring samba. Before changing the configure file, back up the original file:

cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

1.1 Examples on setting password protected Samba share

vi /etc/samba/smb.conf


[global]
workgroup = WORKGROUP
server string = ncu12345678
security = User 
load printers = yes
cups options = raw
[share]
writeable = yes
path = /home/ajohn/dataswitch/windows
#do not use this setting since it will cause all created files owned by root
#admin users = user
force user = ajohn
valid users = ajohn
public = yes
available = yes
guest ok = no
# I changes the permissions to rw-rw-r--
create mask = 664
force create mode = 664
security mask = 664
force security mode = 664

directory mask = 0775
force directory mode = 0775
directory security mask = 0775
force directory security mode = 0775


Save and exit the configuration file.



2. Create Samba User

After you have install samba sever, yous still can’t login samba server. You will need create a samba user :
smbpasswd -a username
‘-a’ switch tell smbpasswd we want to add a new user, username is the user you want to add.

Please take note, username must exist in /etc/passwd file or you will need use ‘useradd’ to create a user in Linux :

sudo /usr/sbin/useradd -d /home/username -s /bin/false -n username
 
This will create a new user with same group name with (told by ‘-n’), but the user can’t login and run any shell command (because you have specfic the login shell is /bin/false by the ‘-s’ switch, if you want allow user to able to login to a shell, replace /bin/false with /bin/sh).

Ok now you have create a new samba user, how about you want delete or disable them? ‘-d’ switch will disable the user to login to samba server:
smbpasswd -d username
If you want to delete a user permanently:
smbpasswd -x username
3. Start the Samba service

sudo /etc/init.d/smb start

Question: If you encounter "access denied error"? check whether you have set SeLinux to disabled or permissive

Configuring Samba on CentOS

1 .Installing samba via yum


yum -y install samba samba-common samba-client


Configuring samba. Before changing the configure file, back up the original file:


cp /etc/samba/smb.conf /etc/samba/smb.conf.orig


Showing you the basic configuration of samba. In this example we are going to share softwares directory. Only samba user can able to save files in this directory.


vi /etc/samba/smb.conf

[global]
workgroup = WORKGROUP
server string =String used to show
security = share
load printers = yes
cups options = raw
[share]
writeable = yes
admin users = emen
path = /softwares
force user = root
valid users = emen
public = yes
available = yes



Save and exit the configuration file.






2. Create Samba User


After you have install samba sever, yous still can’t login samba server. You will need create a samba user :

$ smbpasswd -a username

‘-a’ switch tell smbpasswd we want to add a new user, username is the user you want to add.If you want use your windows login password to log in to samba server, you can define the password as your windows password here. The problem is that you need change your samba server password accordingly when you change your windows password.


Please take note, username must exist in /etc/passwd file or you will need use ‘useradd’ to create a user in Linux :

$ sudo /usr/sbin/useradd -d /home/username -s /bin/false -n username
 

This will create a new user with same group name with (told by ‘-n’), but the user can’t login and run any shell command (because you have specfic the login shell is /bin/false by the ‘-s’ switch, if you want allow user to able to login to a shell, replace /bin/false with /bin/sh).


Ok now you have create a new samba user, how about you want delete or disable them? ‘-d’ switch will disable the user to login to samba server:

$ smbpasswd -d username

If you want to delete a user permanently:

$ smbpasswd -x username

3. Configure iptables to allow conection to the samba server

Check to see whether you have port 137,138,139,443 and 445 open for connection. If not open them in iptables.

$ sudo vim /etc/sysconfig/iptables

$ sudo /etc/init.d/iptables restart

4. Start the Samba service


$ sudo /etc/init.d/smb start

$ sudo /sbin/chkconfig smb on

Add other language support for CentOS

By default, CenOS does not install other languages, to install you can use the following command:

sudo yum install @chinese-support

Add other language support for CentOS

By default, CenOS does not install other languages, to install you can use the following command:

sudo yum install @chinese-support

How to use django-pagination with django-table

How to use django-pagination

django-pagination allows for easy Digg-style pagination without modifying your views.

There are really 5 steps to setting it up with your projects (not including installation, which is covered in INSTALL.txt in this same directory.)
  1. List this application in the INSTALLED_APPS portion of your settings file. Your settings file might look something like:
    INSTALLED_APPS = (
    # ...
    'pagination',
    )
  2. Install the pagination middleware. Your settings file might look something like:
    MIDDLEWARE_CLASSES = (
    # ...
    'pagination.middleware.PaginationMiddleware',
    )
  3. If it's not already added in your setup, add the request context processor. Note that context processors are set by default implicitly, so to set them explicitly, you need to copy and paste this code into your under the value TEMPLATE_CONTEXT_PROCESSORS:
    ("django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request")
  4. Add this line at the top of your template to load the pagination tags:
    {% load pagination_tags %}
  5. Decide on a variable that you would like to paginate, and use the autopaginate tag on that variable before iterating over it. This could take one of two forms (using the canonical object_list as an example variable):
    {% autopaginate object_list %}
    This assumes that you would like to have the default 20 results per page. If you would like to specify your own amount of results per page, you can specify that like so:
    {% autopaginate object_list 10 %}
    Note that this replaces object_list with the list for the current page, so you can iterate over the object_list like you normally would.
  6. Now you want to display the current page and the available pages, so somewhere after having used autopaginate, use the paginate inclusion tag:
    {% paginate %}
    This does not take any arguments, but does assume that you have already called autopaginate, so make sure to do so first.
That's it! You have now paginated object_list and given users of the site a way to navigate between the different pages--all without touching your views.



Continue reading if you use Django-table and pass a table to the template. You will find that it will fail to show the web in paged style , when you trying to use   {% autopaginate table.rows 25 %}. The following code works this out:

{% extends "base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% block title %}{% trans "Demographics" %}{% endblock %}

{% block content %}
   
   
   
   
        {% for column in table.columns %}
       
       
        {% endfor %}
   
   
    {% with table.rows as rows %}
    {% autopaginate rows 25 %}
    {% for row in rows %}
   
           
            {% for value in row %}
           
           
            {% endfor %}
           
    {% endfor %}
    {% paginate %}
    {% endwith %}
   
       
       
{{ column }}
{{ value }}

{% endblock %}

How to use django-pagination with django-table

How to use django-pagination

django-pagination allows for easy Digg-style pagination without modifying your views.

There are really 5 steps to setting it up with your projects (not including installation, which is covered in INSTALL.txt in this same directory.)
  1. List this application in the INSTALLED_APPS portion of your settings file. Your settings file might look something like:
    INSTALLED_APPS = (
        # ...
        'pagination',
    )
  2. Install the pagination middleware. Your settings file might look something like:
    MIDDLEWARE_CLASSES = (
        # ...
        'pagination.middleware.PaginationMiddleware',
    )
  3. If it's not already added in your setup, add the request context processor. Note that context processors are set by default implicitly, so to set them explicitly, you need to copy and paste this code into your under the value TEMPLATE_CONTEXT_PROCESSORS:
    ("django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request")
  4. Add this line at the top of your template to load the pagination tags:
    {% load pagination_tags %}
  5. Decide on a variable that you would like to paginate, and use the autopaginate tag on that variable before iterating over it. This could take one of two forms (using the canonical object_list as an example variable):
    {% autopaginate object_list %}
    This assumes that you would like to have the default 20 results per page. If you would like to specify your own amount of results per page, you can specify that like so:
    {% autopaginate object_list 10 %}
    Note that this replaces object_list with the list for the current page, so you can iterate over the object_list like you normally would.
  6. Now you want to display the current page and the available pages, so somewhere after having used autopaginate, use the paginate inclusion tag:
    {% paginate %}
    This does not take any arguments, but does assume that you have already called autopaginate, so make sure to do so first.
That's it! You have now paginated object_list and given users of the site a way to navigate between the different pages--all without touching your views.



Continue reading if you use Django-table and pass a table to the template. You will find that it will fail to show the web in paged style , when you trying to use   {% autopaginate table.rows 25 %}. The following code works this out:

{% extends "base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% block title %}{% trans "Demographics" %}{% endblock %}

{% block content %}
    <table width="20%" border="2">
    <tr>
    </tr>
    <tr>
        {% for column in table.columns %}
        <td>       
        <th><a href="?sort={{ column.name_toggled }}">{{ column }}</a></th>
        </td>
        {% endfor %}
    </tr>
   
    {% with table.rows as rows %}
    {% autopaginate rows 25 %}
    {% for row in rows %}
   
            <tr>
            {% for value in row %}
            <td > {{ value }} </td>
           
            {% endfor %}
            </tr>
    {% endfor %}
    {% paginate %}
    {% endwith %}
    </table>
{% endblock %}

Import existing Django project into Eclipse with PyDev


**Here the existing Django project means the project is not created within the eclipse environment

1. Create two files within the current Django project: .project file and .pydevproject. Make sure you make the appropriate changes.

.project contents (must replace the MyProject with the project name)



    MyProject
   
   
   
   
       
            org.python.pydev.PyDevBuilder
           
           
       
   
   
        org.python.pydev.pythonNature
   



.pydevproject contents (must replace the path (/MyProject/src) with the actual folders to be in the PYTHONPATH)

In most situtaions /MyProject/src will be replaced with the Django project name.




    Default
    python 2.7
   
   
   
        /MyProject/src
   



2. Open eclipse and use import>>Existing project into Workspace. In the next screen, the root directory is your current django project root.


Import existing Django project into Eclipse with PyDev


**Here the existing Django project means the project is not created within the eclipse environment

1. Create two files within the current Django project: .project file and .pydevproject. Make sure you make the appropriate changes.

.project contents (must replace the MyProject with the project name)

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>MyProject</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.python.pydev.PyDevBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.python.pydev.pythonNature</nature>
    </natures>
</projectDescription>


.pydevproject contents (must replace the path (/MyProject/src) with the actual folders to be in the PYTHONPATH)

In most situtaions /MyProject/src will be replaced with the Django project name.

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
    <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
    <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
    <pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
    </pydev_variables_property>
    <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
        <path>/MyProject/src</path>
    </pydev_pathproperty>
</pydev_project>


2. Open eclipse and use import>>Existing project into Workspace. In the next screen, the root directory is your current django project root.


How to use rsync for transferring files under Linux or UNIX

rsync command common options

  • --delete : delete files that don't exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Task : Copy file from a remote server to a local computer

Copy file /home/tommy/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
$ rsync -v -e ssh tommy@openbsd.nixcraft.in:~/webroot.txt /tmp
Password


Task: Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot


How to use rsync for transferring files under Linux or UNIX

rsync command common options

  • --delete : delete files that don't exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Task : Copy file from a remote server to a local computer

Copy file /home/tommy/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
$ rsync -v -e ssh tommy@openbsd.nixcraft.in:~/webroot.txt /tmp
Password


Task: Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot


RSync backups

Syntax

$ rsync options source destination

Example 1. Synchronize Two Directories in a Local Server

$ rsync -zvr /var/opt/installation/inventory/ /root/temp

In the above rsync example:

    -z is to enable compression
    -v verbose
    -r indicates recursive

Example 2. Preserve timestamps during Sync using rsync -a

rsync option -a indicates archive mode. -a option does the following,

    Recursive mode
    Preserves symbolic links
    Preserves permissions
    Preserves timestamp
    Preserves owner and group

$ rsync -azv /var/opt/installation/inventory/ /root/temp/

Example 3. Synchronize Only One File

To copy only one file, specify the file name to rsync command, as shown below.

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/

Example 4. Synchronize Files From Local to Remote

rsync allows you to synchronize files/directories between the local and remote system.

$ rsync -avz /root/temp/ thegeekstuff@192.168.200.10:/home/thegeekstuff/temp/

Example 5. Synchronize Files From Remote to Local

When you want to synchronize files from remote to local, specify remote path in source and local path in target as shown below.

$ rsync -avz thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 6. Remote shell for Synchronization

rsync allows you to specify the remote shell which you want to use. You can use rsync ssh to enable the secured remote connection.

Use rsync -e ssh to specify which remote shell to use. In this case, rsync will use ssh.

$ rsync -avz -e ssh thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 7. Do Not Overwrite the Modified Files at the Destination

In a typical sync situation, if a file is modified at the destination, we might not want to overwrite the file with the old file from the source.

Use rsync -u option to do exactly that. (i.e do not overwrite a file at the destination, if it is modified). In the following example, the file called Basenames is already modified at the destination. So, it will not be overwritten with rsync -u.

$ rsync -avzu thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 8. Synchronize only the Directory Tree Structure (not the files)

Use rsync -d option to synchronize only directory tree from source to the destination. The below example, synchronize only directory tree in recursive manner, not the files in the directories.

$ rsync -v -d thegeekstuff@192.168.200.10:/var/lib/ .

Example 9. View the rsync Progress during Transfer

When you use rsync for backup, you might want to know the progress of the backup. i.e how many files are copies, at what rate it is copying the file, etc.

rsync –progress option displays detailed progress of rsync execution as shown below.

$ rsync -avz --progress thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 10. Delete the Files Created at the Target

If a file is not present at the source, but present at the target, you might want to delete the file at the target during rsync.

In that case, use –delete option as shown below. rsync delete option deletes files that are not there in source directory.

$ rsync -avz --delete thegeekstuff@192.168.200.10:/var/lib/rpm/ .

Example 11. Do not Create New File at the Target

If you like, you can update (Sync) only the existing files at the target. In case source has new files, which is not there at the target, you can avoid creating these new files at the target. If you want this feature, use –existing option with rsync command.

$ rsync -avz --existing root@192.168.1.2:/var/lib/rpm/ .

Example 12. View the Changes Between Source and Destination

This option is useful to view the difference in the files or directories between source and destination.-i option displays the item changes.

$ rsync -avzi thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 13. Include and Exclude Pattern during File Transfer

rsync allows you to give the pattern you want to include and exclude files or directories while doing synchronization.

$ rsync -avz --include 'P*' --exclude '*' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 14. Do Not Transfer Large Files

You can tell rsync not to transfer files that are greater than a specific size using rsync –max-size option.

$ rsync -avz --max-size='100K' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

max-size=100K makes rsync to transfer only the files that are less than or equal to 100K. You can indicate M for megabytes and G for gigabytes.

Use wget to repeat download the similar items from a site

1.This command will repeat the wget command for each number enumerated in the { }

wget -nd http://www.cracked.com/blog/wp-content/uploads/2009/12/zorklon{1,2,3,4,5}.jpg

2. use -i option. You can put all the links in one txt file and use -i option to download them one by one.

wget -i fedoraisos.txt

3. Some other options

-c to resume an interrupted download session

--user=user_name

--password=password

--user-agent=agent-string: used when a site denies access to non-browser user agents.

Use wget to repeat download the similar items from a site

1.This command will repeat the wget command for each number enumerated in the { }

wget -nd http://www.cracked.com/blog/wp-content/uploads/2009/12/zorklon{1,2,3,4,5}.jpg

2. use -i option. You can put all the links in one txt file and use -i option to download them one by one.

wget -i fedoraisos.txt

3. Some other options

-c to resume an interrupted download session

--user=user_name

--password=password

--user-agent=agent-string: used when a site denies access to non-browser user agents.

Oil filter wrench cap for 09' Toyota Highalnder

Last week I was trying to change engine oil for my 09 highlander. But I had a hard time to take the engine oil filter cap off. I have tried couple wrench caps from Auto Zone. But they did not work. If you are in the same situation me, try this tool from Amazon.

Oil filter wrench cap for 09' Toyota Highalnder

Last week I was trying to change engine oil for my 09 highlander. But I had a hard time to take the engine oil filter cap off. I have tried couple wrench caps from Auto Zone. But they did not work. If you are in the same situation me, try this tool from Amazon.

CPAN error: failed with code[400] message[URL must be absolute}

While I was trying to install Imager::QRCode using cpan, I have this problem: failed with code[400] message[URL must be absolute]

Searching online I found that my urllist for cpan is empty. To correct problem:

run this command with in cpan O conf urllist push "Your_cpan_mirror_url" for example,

S sudo cpan

cpan> o conf urllist push http://cpan.yahoo.com/

Here are other o conf related commands for use:

To view the urllist: o conf urllist

To remove the first url from the urllist: o conf urllist shift

To save the configuration after you made modification: o conf commit

CPAN error: failed with code[400] message[URL must be absolute}

While I was trying to install Imager::QRCode using cpan, I have this problem: failed with code[400] message[URL must be absolute]

Searching online I found that my urllist for cpan is empty. To correct problem:

run this command with in cpan O conf urllist push "Your_cpan_mirror_url" for example,

S sudo cpan

cpan> o conf urllist push http://cpan.yahoo.com/

Here are other o conf related commands for use:

To view the urllist: o conf urllist

To remove the first url from the urllist: o conf urllist shift

To save the configuration after you made modification: o conf commit

Cannot print a pdf file?

Because you forget your password?

Try this command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output_file.pdf -c .setpdfwrite -f source.pdf

If you want to combine more than one pdf file into one pdf file:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=new_3000.pdf -c .setpdfwrite -f /mnt/ncsfile01/3000/*.pdf

Cannot print a pdf file?

Because you forget your password?

Try this command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output_file.pdf -c .setpdfwrite -f source.pdf

If you want to combine more than one pdf file into one pdf file:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=new_3000.pdf -c .setpdfwrite -f /mnt/ncsfile01/3000/*.pdf

Add Printer to CentOS

 Before adding printer you need have the printer IP address
 Launch add printer wizard from command line: sudo system-config-printer
 New printer >> Give a name for the printer you want to add >>choose APPSocket/HP JetDirect in select connection >> put down the printer ip address in hostname field and leave port number at 9100 >> choose your printer type.

Add Network Printer to CentOS/Ubuntu

 Before adding printer you need have the printer IP address: you can print it out from the printer configuration


1. make sure CUPS is running in your system

[sourcecode language="bash"]
sudo /etc/init.d/cups start
[/sourcecode]


2. Launch add printer wizard from command line

[sourcecode language="bash"]
sudo su -
system-config-printer
[/sourcecode]


3. New printer >> Give a name for the printer you want to add >>choose APPSocket/HP JetDirect in select connection >> put down the printer ip address in hostname field and leave port number at 9100 >> choose your printer type.

4. select printer from database (HP)

5. model: since there is no support for my printer model HP4700 I choose Laserjet 4350 and Postscript as Driver option

Showing hisotry of your Linux commands

1. If you want to show wehen the command was issued:

$ export HISTTIMEFORMAT='%F %T '

$ history > file_name

2. Search the history using Control+R

 

Showing hisotry of your Linux commands

1. If you want to show wehen the command was issued:

$ export HISTTIMEFORMAT='%F %T '

$ history > file_name

2. Search the history using Control+R

 

Visit websense blocked sites?

Are you tied of the following message?

"Content blocked by your organization

Reason:

This Websense category is filtered: Explicitly Blocked."

If you answer yes, try to visit the site though here:

https://proxy1plus.appspot.com/


 

Visit websense blocked sites?

Are you tied of the following message?

"Content blocked by your organization

Reason:

This Websense category is filtered: Explicitly Blocked."

If you answer yes, try to visit the site though here:

https://proxy1plus.appspot.com/


 

Curious which verison of the CentOS you are running?

try typing uname -a in the command line

if you see

Linux XXXXXX 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Then you are running 64 bit of CentOS.

Command cat /etc/redhat-release  will show you the version of theCentOS

Curious which verison of the CentOS you are running?

try typing uname -a in the command line

if you see

Linux XXXXXX 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Then you are running 64 bit of CentOS.

Command cat /etc/redhat-release  will show you the version of theCentOS

Do not update the Creeky Ipad's firmware!

Do not update the Creepy Ipad's firmware!

Or you will probably enter the endless "recovery mode" loop. It happened to me one time before while I was updating the firmware.  And it happened again. I should never trust AP@LE. To get out the loop I have tried many ways I found online, however all most all of them do not work.

Try the following methods first if it happens to you.

Hold on booth home key and power key for at least 10 seconds, ipad will reboot. If you are lucky it will out of the recovery mode by doing so. ---Good for you.

The upper method works for me last time, but does not work this time. The only way works is do the following:

1. Uninstall old version of the iTunes and reboot your computer

2. Reinstall the most updated iTunes

3. Go to c:\ windows\system32\drivers\etc\ to locate the host file, delete the following two lines from the host file:

74.208.10.249 gs.apple.com
#127.0.0.1 gs.apple.com

4. Open iTunes and redo the recovery.

===============================

Unsuccessful methods:

Here are some others recommended to do with the "endless recovery mode":

1. Enter the DFU mode:

DFU mode as opposed to Recovery Mode, requires a bit of timing and can take practice so if at first you don’t succeed, don’t be afraid to keep trying.
  • Plug your iPhone, iPod touch, or iPad into your Mac or Windows PC and make sure iTunes is running.
  • Hold down both the Sleep Button (on top of your device) and the Home Button (on the front underneath the screen).
  • Keep them both held down from about 10 seconds. (If you see the Apple logo, you’ve held them too long and will need to start again.)
  • Let go of the Sleep Button but keep holding the Home Button for about 5 seconds. (If you see the “Plus into iTunes” screen than you held it too long and will need to start again.)
  • If the screen stays black, that’s it! Your iPhone, iPod touch, or iPad should now be in DFU mode.
2. Use TinyUmbrella, which requires you are able to enter the ipad's DFU mode:
  • Download TinyUmbrella (Fix Recovery) for iOS 4.3.x (Windows | Mac)
  • Download Zlib1.dll from here and place it in the same directory in which fixrecovery43.exe is present.
  • Launch iTunes and plug your iPhone into your PC or Mac via USB cable. Let iTunes run in background and use the following instructions to put your iPhone into DFU mode:
    • Hold down the Home+Power button simultaneously for 10 seconds.
    • After 10 seconds, release the Power button but keep holding the Home button until iTunes detects your iPhone into DFU mode.
    • Do not close iTunes. Let it run in the background.
  • Launch fixrecovery43.exe and wait while it kicks your iPhone out of recovery mode loop. Make sure you have an active internet connection because fix recovery will be needing to fetch DFU and firmware image from Apple servers. Whole process usually takes less than a minute.
3. Try using the Recboot and TinyUmbrella to kick you out of the recovery mode.

Do not update the Creeky Ipad's firmware!

Do not update the Creepy Ipad's firmware!

Or you will probably enter the endless "recovery mode" loop. It happened to me one time before while I was updating the firmware.  And it happened again. I should never trust AP@LE. To get out the loop I have tried many ways I found online, however all most all of them do not work.

Try the following methods first if it happens to you.

Hold on booth home key and power key for at least 10 seconds, ipad will reboot. If you are lucky it will out of the recovery mode by doing so. ---Good for you.

The upper method works for me last time, but does not work this time. The only way works is do the following:

1. Uninstall old version of the iTunes and reboot your computer

2. Reinstall the most updated iTunes

3. Go to c:\ windows\system32\drivers\etc\ to locate the host file, delete the following two lines from the host file:

74.208.10.249 gs.apple.com
#127.0.0.1 gs.apple.com

4. Open iTunes and redo the recovery.

===============================

Unsuccessful methods:

Here are some others recommended to do with the "endless recovery mode":

1. Enter the DFU mode:

DFU mode as opposed to Recovery Mode, requires a bit of timing and can take practice so if at first you don’t succeed, don’t be afraid to keep trying.
  • Plug your iPhone, iPod touch, or iPad into your Mac or Windows PC and make sure iTunes is running.
  • Hold down both the Sleep Button (on top of your device) and the Home Button (on the front underneath the screen).
  • Keep them both held down from about 10 seconds. (If you see the Apple logo, you’ve held them too long and will need to start again.)
  • Let go of the Sleep Button but keep holding the Home Button for about 5 seconds. (If you see the “Plus into iTunes” screen than you held it too long and will need to start again.)
  • If the screen stays black, that’s it! Your iPhone, iPod touch, or iPad should now be in DFU mode.
2. Use TinyUmbrella, which requires you are able to enter the ipad's DFU mode:
  • Download TinyUmbrella (Fix Recovery) for iOS 4.3.x (Windows | Mac)
  • Download Zlib1.dll from here and place it in the same directory in which fixrecovery43.exe is present.
  • Launch iTunes and plug your iPhone into your PC or Mac via USB cable. Let iTunes run in background and use the following instructions to put your iPhone into DFU mode:
    • Hold down the Home+Power button simultaneously for 10 seconds.
    • After 10 seconds, release the Power button but keep holding the Home button until iTunes detects your iPhone into DFU mode.
    • Do not close iTunes. Let it run in the background.
  • Launch fixrecovery43.exe and wait while it kicks your iPhone out of recovery mode loop. Make sure you have an active internet connection because fix recovery will be needing to fetch DFU and firmware image from Apple servers. Whole process usually takes less than a minute.
3. Try using the Recboot and TinyUmbrella to kick you out of the recovery mode.

Linux find and replace text within all files within a directory



There is a fast way to replace all the occurrences of one world within a certain directory including subdirectory by using a one line Linux code (by using Perl):



find /path/to/start/from/ -type f | xargs perl -pi -e 's/old_word/new_word/g'





REMEMBER ALWAYS BACKUP BEFORE DOING SOMETHING
If you want to do word replacement using the vim
:%s/search/replace/g                     whole file
:2,12s/search/replace/g                 from line 2 to line 12

Linux find and replace text within all files within a directory



There is a fast way to replace all the occurrences of one world within a certain directory including subdirectory by using a one line Linux code (by using Perl):



find /path/to/start/from/ -type f | xargs perl -pi -e 's/old_word/new_word/g'





REMEMBER ALWAYS BACKUP BEFORE DOING SOMETHING
If you want to do word replacement using the vim
:%s/search/replace/g                     whole file
:2,12s/search/replace/g                 from line 2 to line 12

Install a new version of the Python on CentOS without overwriting the system's python installation

Install a new version of the Python on CentOS without overwriting the system's python installation
** You have to decide where to install it based on your needs. If you want to run web server later using this copy of the Python, you may not want to install it in your home directory. Most popular place to go is /opt/.
The default Python comes with the CentOS is version 2.4 which can not meet the requirements of some programs. Here is an instruction of installing a separate newer version of the Python on CnetOS.
Prepare the source code
  1. cd
  2. wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  3. tar –zvxf Python-2.7.2.tgz
  4. cd Python-2.7.2
  5. configure python so it will not overwriting the system’s default python
    ./configure –prefix= /usr/local/opt/python2.7 --with-threads --enable-shared
1)     --enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2)        However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2. The error message is "ld cannot find lpython2.7". Here is a solution to that:
$ cd /usr/lib64
$ sudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
   $ sudo ln -s libpython2.7.so.1.0  libpython2.7.so

  1. make and install
  $ make
 $ make install
Now you have successfully installed a fully functional copy of the python library. In order to use it you can do some configuration for this version of the python.
  1. add the following line to user’s .bashrc to create an alias, so you do not need reboot to start using the alias
    alias python='/usr/local/opt/python2.7/bin/python'
2.  Make a symbolic link in the /usr/bin folder:
    $ ln –s /usr/local/python2.7/bin/python /usr/bin/python2.7
3. to make a permanent change then you can run the following as root:
     ln -f /usr/local/python2.7/bin/python /usr/local/bin/python
  1. Configure ld to find your shared libs:
a. create file opt-python2.7.conf under /etc/ld.so.conf.d folder
b. add /usr/local/python2.7/lib into the created file
c. run $ sudo /sbin/ldconfig

After the installation of the new versions of the Python you might need to install the setuptools and pip to work with this version of the Python:
1. Install setuptools
a.         cd
b.        wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
c.        tar -zvxf setuptools-0.6c11.tar.gzll
d.        cd setuptools-0.6c11
e.        python2.7 setup.py build  ###here use the newly installed python to make sure you are installing it for it
f.        python2.7 setup.py install

     2 Install pip

        Follow the same operation process for installing setuptools.  After installing the pip you may want to make a symbolic link for it in the /usr/bin folder
sudo ln –s /usr/local/python2.7/bin/pip /usr/bin/pip2.7









Reference:

1. Thanks http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/ for tips on overcoming the errors while installing the psycopg2 by link thelibraries to /usr/lib64.

2. http://blog.hackedexistence.com/mediatemple-centos-5-5-ve-server-build-django-1-3-python-2-7-mysql-5-5-php-5-3

Install a new version of the Python on CentOS without overwriting the system's python installation

** You have to decide where to install it based on your needs. Most popular place to go is /opt/.

1. Install epel (extra packages for enterprise linux). This will add the epel repo to yum and give us a running start at some normally unavailable packages. It also provides some updates to existing repo packages:

To install EPEL follow this link: http://b2ctran.wordpress.com/2013/03/08/enable-epel-repository-on-centos/

2. Preinstall dependencies: development tools, ssl and zlib and some other packages which will be needed by python
$ yum -y groupinstall 'Development Tools'
$ yum -y  install openssl-devel zlib zlib-devel
$ yum install -y gdbm-devel sqlite-devel tk-devel ncurses-devel bzip2-devel readline-devel db4-devel

3. Prepare python2.7 source code

$ cd
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
$ tar –zvxf Python-2.7.2.tgz
$ cd Python-2.7.2

Configure the Modules/Setup.dist to enable the gzip and readline support by uncomment the associated entries.
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib –lz
#readline realine.c -lreadline –ltermcap

4. configure python so it will not overwriting the system’s default python
./configure –prefix= /opt/python2.7 --with-threads --enable-shared

1)--enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2) However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2.

The error message is "ld cannot find lpython2.7".

Here is a solution to that:

$ cd /usr/lib64
$ sudo ln -s /opt/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
$ sudo ln -s libpython2.7.so.1.0 libpython2.7.so

5. make and install

$ make
$ sudo make install

6. Now we need to update BASH so that it knows about the new shared libraries that we have put on the system.

$ sudotouch /etc/ld.so.conf.d/opt-python2.7.conf
add put /opt/python2.7/lib in the created file
$ sudo /sbin/ldconfig

7. install setuptools and pip:

$wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
$sudo sh setuptools-0.6c11-py2.7.egg

if you encounter python2.7 could not found error, the following will probably fix it:
$ sudo ln -s /opt/python2.7/bin/python  /usr/bin/python2.7

After installing easy_install you can install pip: sudo /opt/python2.7/bin/easy_install pip

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...