Category Archives: Centos

Shared Folder Between Windows and Oracle VM Virtual Box

  1.  Create an folder on Windows. For example, C:\Shared
  2.  In Oracle VM VirtualBox Manager select Settings for the OS installed and choose the folder to be shared with OS running on VM. In our case, OS is Centos 7.2 and the shared folder is C:\Shared

sharedfolder_centos7_to_windows7

3. login to Centos and create Shared folder. For example, /media/Shared

4. Execute the command mount -t vboxsf Shared /media/Shared/ 

Please note that, first 2 steps should be followed on windows. Next 2 steps should be followed on Centos (VM instance)

We should able to shared folders and files between Windows and Centos after following these 4 steps.

Passwordless SSH

1. Generate public and private keys using ssh-key-gen

[root@localhost .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
7c:a8:e5:63:4c:f0:77:4c:e4:b1:b4:7f:16:91:73:2b root@localhost.localdomain
The key’s randomart image is:
+–[ RSA 2048]—-+
| + ..|
| + + oo|
| . = .+|
| + . o E ..|
| S o o o o|
| * o . o |
| . = |
| . . |
| |
+—————–+

2. Copy the generated local machine’s public key to remote-host using ssh-copy-id
ssh-copy-id command will append the keys to the remote-host’s .ssh/authorized_key.

[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 10.21.170.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
root@10.21.170.1’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘10.21.170.1’”
and check to make sure that only the key(s) you wanted were added.

3. Login to remote machine using ssh without issuing password

[root@localhost .ssh]# ssh 10.21.170.1
Last login: Tue Oct 11 15:55:44 2016 from root

Backup postgres database and tables

Backup

#login as root

#For single table

pg_dump -U postgres -d TESTDB -t users > /tmp/users.sql

#For multiple tables

pg_dump -U postgres -d TESTDB -t users -t customer -t account > /tmp/testdb.sql

#For complete database
pg_dump -U postgres TESTDB > /tmp/TESTDB.sql

Restore

#login as postgres user

psql -U postgres -d TESTDB < /tmp/TESTDB.sql

 

 

install rar/unrar

[root@localhost bin]# wget http://pkgs.repoforge.org/unrar/unrar-4.0.7-1.el6.rf.x86_64.rpm
–2016-06-27 14:38:50–  http://pkgs.repoforge.org/unrar/unrar-4.0.7-1.el6.rf.x86_64.rpm
Resolving pkgs.repoforge.org (pkgs.repoforge.org)… 78.46.17.228
Connecting to pkgs.repoforge.org (pkgs.repoforge.org)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://rpmforge.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:38:51–  http://rpmforge.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm
Resolving rpmforge.sw.be (rpmforge.sw.be)… 78.46.17.228
Connecting to rpmforge.sw.be (rpmforge.sw.be)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://tree.repoforge.org/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:38:51–  http://tree.repoforge.org/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm
Resolving tree.repoforge.org (tree.repoforge.org)… 78.46.17.228
Connecting to tree.repoforge.org (tree.repoforge.org)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:38:52–  http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/unrar-4.0.7-1.el6.rf.x86_64.rpm
Resolving apt.sw.be (apt.sw.be)… 193.1.193.67
Connecting to apt.sw.be (apt.sw.be)|193.1.193.67|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 109432 (107K) [application/x-redhat-package-manager]
Saving to: ‘unrar-4.0.7-1.el6.rf.x86_64.rpm’

100%[=========================================================================================================================================================================>] 109,432     91.4KB/s   in 1.2s

2016-06-27 14:38:54 (91.4 KB/s) – ‘unrar-4.0.7-1.el6.rf.x86_64.rpm’ saved [109432/109432]

[root@localhost bin]# rpm -Uvh unrar-4.0.7-1.el6.rf.x86_64.rpm
warning: unrar-4.0.7-1.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing…                          ################################# [100%]
Updating / installing…
1:unrar-4.0.7-1.el6.rf             ################################# [100%]
[root@localhost bin]# wget http://pkgs.repoforge.org/rar/rar-3.8.0-1.el6.rf.x86_64.rpm
–2016-06-27 14:39:17–  http://pkgs.repoforge.org/rar/rar-3.8.0-1.el6.rf.x86_64.rpm
Resolving pkgs.repoforge.org (pkgs.repoforge.org)… 78.46.17.228
Connecting to pkgs.repoforge.org (pkgs.repoforge.org)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://rpmforge.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:39:17–  http://rpmforge.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm
Resolving rpmforge.sw.be (rpmforge.sw.be)… 78.46.17.228
Connecting to rpmforge.sw.be (rpmforge.sw.be)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://tree.repoforge.org/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:39:18–  http://tree.repoforge.org/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm
Resolving tree.repoforge.org (tree.repoforge.org)… 78.46.17.228
Connecting to tree.repoforge.org (tree.repoforge.org)|78.46.17.228|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm [following]
–2016-06-27 14:39:18–  http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rar-3.8.0-1.el6.rf.x86_64.rpm
Resolving apt.sw.be (apt.sw.be)… 193.1.193.67
Connecting to apt.sw.be (apt.sw.be)|193.1.193.67|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 216720 (212K) [application/x-redhat-package-manager]
Saving to: ‘rar-3.8.0-1.el6.rf.x86_64.rpm’

100%[=========================================================================================================================================================================>] 216,720      125KB/s   in 1.7s

2016-06-27 14:39:20 (125 KB/s) – ‘rar-3.8.0-1.el6.rf.x86_64.rpm’ saved [216720/216720]

[root@localhost bin]# rpm -Uvh rar-3.8.0-1.el6.rf.x86_64.rpm
warning: rar-3.8.0-1.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing…                          ################################# [100%]
Updating / installing…
1:rar-3.8.0-1.el6.rf               ################################# [100%]
[root@localhost bin]#

Changing Timezone in Centos

[root@localhost logs]# date
Thu Jun 23 20:52:10 IST 2016
[root@localhost logs]# ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
[root@localhost logs]# date
Thu Jun 23 17:22:59 CEST 2016

 

NOTE:

We need to remove the /etc/localtime if it is already present

 

Useful Centos Commands

#Extract unrar files

[rsengodan@contossrv tmp]$ unrar e Test.rar

UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal

Extracting from Test.rar

Extracting  performance.log                                           OK
Extracting  systemerror.log                                            OK
All OK
[rsengodan@centossrv tmp]$ ls -ltr

#Find string in current and subdirectories

find . -exec grep “www.utm” ‘{}’ \; -print –> to find out the string

#Copy files to remote server using scp utility

[rsengodan@centossrv tmp]$ scp -r test.log test1.log rsengodan@10.21.100.101:/tmp

#Extract unique token from file

[21 Mar 2017 11:45:53:462] [Thread-2] -INFO  -SYS_ERR: java.io.FileNotFoundException: /usr/users/ravi/user.xml (No such file or directory)
[21 Mar 2017 11:45:54:462] [Thread-2] -INFO  -SYS_ERR: java.io.FileNotFoundException: /usr/users/kumar/user.xml (No such file or directory)
[21 Mar 2017 11:45:54:462] [Thread-2] -INFO  -SYS_ERR: java.io.FileNotFoundException: /usr/users/guna/user.xml (No such file or directory)
[21 Mar 2017 11:45:54:462] [Thread-2] -INFO  -SYS_ERR: java.io.FileNotFoundException: /usr/users/aadhav/user.xml (No such file or directory)
[21 Mar 2017 11:45:54:462] [Thread-2] -INFO  -SYS_ERR: java.io.FileNotFoundException: /usr/users/moni/user.xml (No such file or directory)

cat sample.log | grep “java.io.FileNotFoundException:” | awk ‘{print $9;}’ | sort | uniq

output:

/usr/users/ravi/user.xml
/usr/users/kumar/user.xml
/usr/users/guna/user.xml
/usr/users/aadhav/user.xml
/usr/users/moni/user.xml