Wednesday, 22 July 2015

Infinite Arithmetic Precision Shell Script/arithmetic operations

#!/bin/bash

addition()
{
sum=$(echo $a + $b | bc)
echo $sum
}
subtraction()
{
sum=$(echo $a - $b | bc)
echo $sum
}
multiplication()
{
sum=$(echo $a \* $b | bc)
echo $sum
}
division()
{
sum=$(echo $a / $b | bc)
echo $sum
}
menu()
{
echo "Enter any Two Numbers:"
read  a b
echo $a $b
}
menu
addition $a $b
subtraction $a $b
multiplication $a $b
division $a $b

Tuesday, 21 July 2015

How to Encrypt files on centos6/Rhel/Fedora

How to Encrypt files on centos6/Rhel/Fedora

GNU Privacy Guard (GnuPG) is the backend encryption engine.

Before you can use Gnupg you need to create key pair by "gpg --gen-key"

#gpg --gen-key

gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)

Your selection? 1

RSA keys may be between 1024 and 4096 bits long.

What keysize do you want? (2048) 1024

Requested keysize is 1024 bits

Please specify how long the key should be valid.

         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years

Key is valid for? (0) 2

Key expires at Fri 24 Jul 2015 10:58:51 AM IST
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: shaurya

Email address: xxxxxxxxxx

Comment:xxxxxxxxxxxxxx

You selected this USER-ID:
    "shaurya (xxxxxxxxxxxxxxx) <xxxxxxxxxx>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o

You need a Passphrase to protect your secret key.

gpg: problem with the agent: Not implemented

We need to generate a lot of random bytes. It is a good idea to perform

some other action (type on the keyboard, move the mouse, utilize the

disks) during the prime generation; this gives the random number

generator a better chance to gain enough entropy.

We need to generate a lot of random bytes. It is a good idea to perform

some other action (type on the keyboard, move the mouse, utilize the

disks) during the prime generation; this gives the random number

generator a better chance to gain enough entropy.

gpg: key 44759702 marked as ultimately trusted

public and secret key created and signed.

gpg: checking the trustdb

gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model

gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u

gpg: next trustdb check due at 2015-07-24

pub   1024R/44759702 2015-07-22 [expires: 2015-07-24]

      Key fingerprint = 06EE 569F DC55 18F0 4E4C  16E3 64D6 389C 4475 9702

uid                  shaurya (xxxxxxxxxxx) <xxxxxxxxxxxxxxx>

sub   1024R/45D6A561 2015-07-22 [expires: 2015-07-24]

To encrypt "gpg --encrypt --default-recipient-self filename"

[root@sk ~]# gpg --encrypt --default-recipient-self test.txt

 

And this will create filename.gpg which is encrypted.

How to Install yad(shell script gui) on centos6/Rhel/Fedora

How to Install yad(shell script gui) on centos6/Rhel/Fedora

 

YAD  is a program that will display GTK+ dialogs, and return (either in the return code, or on standard output) the users input. This allows you
to present information, and ask for information from the user, from all manner of shell scripts.

YAD is the fork of Zenity program.

#cd /opt

#wget https://yad.googlecode.com/files/yad-0.25.1.tar.xz

#tar -xvf yad-0.25.1.tar.xz

#cd yad-0.25.1

#./configure

#make

#make install

you can read manual of yad by below command

#man yad /*for how to use*/

examples for how to use yad

#yad --calendar

example script to get the

#!/bin/bash

frmdata=$(yad --title "Login" --form --field "Username" --field="Password")


frmaddr=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }')
frmname=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }')

echo $frmaddr > test.txt
echo $frmname >> test.txt

How to Install TeamViewer 10 on CentOS, RHEL & Fedora

How to Install TeamViewer 10 on CentOS, RHEL & Fedora

1.Install TeamViewer on CentOS, RHEL & Fedora
-------------------------------------------------------------------------------------
#yum install http://download.teamviewer.com/download/teamviewer.i686.rpm
            or
#cd /opt
#wget http://download.teamviewer.com/download/teamviewer.i686.rpm
#rpm --import http://www.teamviewer.com/link/?url=354858
#yum install libpng12.so.0
#rpm -Uvh teamviewer.i686.rpm
-------------------------------------------------------------------------------------
2.Launch TeamViewer
-------------------------------------------------------------------------------------
#teamviewer
-------------------------------------------------------------------------------------

Webacula Installation and Configuration with postgresql on Centos 6

Webacula Installation and Configuration with postgresql on Centos 6



Install Apache Server:
#yum install httpd
#chkconfig httpd on
#service httpd start
1.Download webacula-7.0.0 from the below link.
2.Untar the file.
#cd /root/Downloads
#tar -zxvf webacula-7.0.0.tar.gz
3.copy the directory to /var/www/html
#cp webacula-7.0.0 /var/www/html/
4.Rename the directory.
#mv webacula-7.0.0 webacula
5.Check the System Requirements.
#cd /var/www/html/webacula/install/
#./check_system_requirements.php
Webacula check System Requirements...
Current MySQL version = 5.5.41 OK
Current PostgreSQL version = 9.2.4 OK
Current Sqlite version = 3.6.20 OK
Current PHP version = 5.3.3 OK
php pdo installed. OK
php gd installed. OK
php xml installed. OK
php dom installed. OK
Warning. PHP extension pdo_mysql not installed.
php pdo_pgsql installed. OK
php pdo_sqlite installed. OK
php-dom, php-xml installed. OK
7.I am using postgresql database so, i am ignoring this warning.
8.If you don't have these requirements then you can install by the below commands.
Go to pbone.net website and search for php-pgsql-5.3.3-40.el6_6.x86_64.
Download that package.
Install by the below command.
#rpm -ivh php-pgsql-5.3.3-40.el6_6.x86_64
It will ask for Dependency Packages.
So,you have to install dependency packages also.
Download all the below packages from pbone.net.
php-cli-5.3.3-40.el6_6.x86_64
php-5.3.3-40.el6_6.x86_64
php-gd-5.3.3-40.el6_6.x86_64
php-xml-5.3.3-40.el6_6.x86_64
php-common-5.3.3-40.el6_6.x86_64
php-pdo-5.3.3-40.el6_6.x86_64
After downloading all packages install by the below command.
#rpm -ivh <package name>
9.After installing all packages again check_system_requirements.
10.Download ZendFramework-1.11.5-minimal. Copy the directory ZendFramework-1.11.5-minimal/library/Zend to /var/www/html/webacula/library/
#cp ZendFramework-1.11.5-minimal/library/Zend /var/www/html/webacula/library/
11.Go to directory /var/www/html/webacula/application
#cd /var/www/html/webacula/application
Edit the config.ini file.
#vim config.ini
change the below lines as following:
db.adapter = PDO_PGSQL
db.config.host = localhost
db.config.username = postgres
db.config.password = postgres
db.config.dbname = bacula
def.timezone = "Asia/Kolkata"
bacula.sudo = ""
bacula.bconsole = "/opt/bacula/bin/bconsole"
bacula.bconsolecmd = "-n -c /opt/bacula/bin/bconsole.conf"
:wq
Create system group account (if not yet created) :
#groupadd bacula
Add apache to group:
usermod -aG bacula apache
Without using sudo
chown root:bacula /opt/bacula/bin/bconsole
chmod u=rwx,g=rx,o= /opt/bacula/bin/bconsole
chown root:bacula /opt/bacula/bin/bconsole.conf
chmod u=rw,g=r,o= /opt/bacula/bin/bconsole.conf
Edit application/config.ini
bacula.sudo = ""
bacula.bconsole = "/opt/bacula/bin/bconsole"
Here I am using without sudo.
With sudo
Edit application/config.ini
bacula.sudo = "/usr/bin/sudo"
bacula.bconsole = "/opt/bacula/sbin/bconsole"
Run visudo and changes
# (!!! comment here !!!) Defaults requiretty
apache ALL=NOPASSWD: /opt/bacula/sbin/bconsole
Check out the run bconsole :
# su -l apache -s /bin/sh \
-c "/usr/bin/sudo /opt/bacula/sbin/bconsole -n -c /opt/bacula/etc/bconsole.conf"
Edit webacula.conf
#cd /var/www/html/webacula/install/apache
#vim webacula.conf
Change the paths to /var/www/html instead of /usr/share.
Copy the file to /etc/httpd/conf.d/webacula.conf
#cp /var/www/html/webacula/install/apache/webacula.conf /etc/httpd/conf.d/webacula.conf
mod rewrite
Setup mod rewrite see html/.htaccess.
necessary.
Edit RewriteBase parameter if
NOTE. Specific directories on your system may be different.
Check mod rewrite installed :
$ apachectl -t -D DUMP_MODULES 2>&1 | grep rewrite
rewrite_module (shared)
PHP
Increase values in /etc/php.ini :
memory_limit = 32M
max_execution_time = 3600
Edit db.conf file
#cd /var/www/html/webacula/install/
#vim db.conf
db_name="bacula"
db_user="postgres"
db_pwd="postgres"
To set webacula_root_pwd you have to come out of the file and do like below
#./password-to-hash.php password
whatever your pssword is type instead of password in the above command.
Copy the output and pasteit into webacula_root_pwd in db.conf file.
Save the file by :wq
Next create Webacula tables, Webacula built-in roles and Webacula built-in
users.
For MySQL:
#cd install/MySql
For PostgreSQL:
#cd install/PostgreSql
For Sqlite:
#cd install/SqLite
And further run scripts for your DBMS is running on localhost:
#./10_make_tables.sh
#./20_acl_make_tables.sh
Now you can run webacula monitoring by

How to run Postgresql as a service

How to run Postgresql as a service

#vim /etc/init.d/postgresql

Copy the below Script to /etc/init.d/postgresql

#!/bin/sh -e
# description: Postgresql SQL Server
# chkconfig: 2345 99 00
PGVER='9.2'
BINPATH="/opt/PostgreSQL/9.0/postgres/bin/"
PGUSER='postgres'
PGLOG='/opt/PostgreSQL/9.0/postgres/data/logfile'
PGDIR='/opt/PostgreSQL/9.0/postgres/data'

start()
{
cd $BINPATH
su - $PGUSER -c "$BINPATH/pg_ctl -D $PGDIR -l $PGLOG start"
}

stop()
{
cd $BINPATH
su - $PGUSER -c "$BINPATH/pg_ctl -D $PGDIR -l $PGLOG stop"
}


case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

exit 0

and save it by :wq

#chkconfig postgresql on /*start the postgresql while boot*/

#service postgresql start

How to Install Postgresql-9.0.1 by Source file

How to Install Postgresql-9.0.1 by Source file

Download postgresql-9.0.1.tar.gz:
#cd /opt

#wget https://ftp.postgresql.org/pub/source/v9.0.1/postgresql-9.0.1.tar.gz

Installation Postgresql database:

Postgresql installation path = /opt/PostgreSQL/9.0/postgres

#mkdir -p /opt/PostgreSQL/9.0/postgres  /* Create postgres installation directory path*/

#tar -zxvf postgresql-9.0.1.tar.gz         /*extract postgresql software*/

# cd postgresql-9.0.1            /*Go to Source of postgresql source Directory */

#./configure --prefix=/opt/PostgreSQL/9.0/postgres     /*Configuration with installation path*/

#make        /*Compile the postgresql and postgresql.log will be created*/

#make install

Set postgresql environment path:

edit .bash_profile
#cd

#vi .bash_profile

Original .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:
export PATH
---------------------------------------------------EOF-------------------------------

Change .bash_profile as follows:

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/opt/PostgreSQL/9.0/posgres/bin:
LD_LIBRARY_PATH=/opt/PostgreSQL/9.0/postgres/lib
export PATH LD_LIBRARY_PATH
---------------------------------------------------EOF-------------------------------

#source .bash_profile        /*source the bash profile*/

#which postgres         /*verify the installation path*/

Create postgres user with /opt/PostgreSQL/9.0/postgres home directory:

#useradd  -b /opt/PostgreSQL/9.0  postgres
       
#passwd postgres    /*set password for postgres user*/

#mkdir /opt/PostgreSQL/9.0/postgres/data /*create postgres data directory for initiating database*/

change ownership of postgres of data directory:

#chown -R postgres  /opt/PostgreSQL/9.0/postgres/data    

Go to postgres user and initiate database:

#su – postgres

#/opt/PostgreSQL/9.0/postgres/bin/initdb  -D  /opt/PostgreSQL/9.0/postgres/data  /*Initiating database*/

#/opt/PostgreSQL/9.0/postgres/bin/postgres -D /opt/PostgreSQL/9.0/postgres/data/ > /opt/PostgreSQL/9.0/postgres/logfile/ 2>&1 & /*Start database server*/