Friday, 16 October 2015

Requisites / difference between 'require and require_in' in SaltStack:

     The Salt requisite system is used to create relationships between states. You can find more details about Requisites on here

require:

* This is the most basic requisite which allows us to specify that one state requires another state to be run successfully first.

* Also ensures correct ordering and the requiring states runs only if the required state ran successfully.

Ex:

# cat req.sls
require_check: # REQUIRING STATE
 cmd.run:
  - name: echo FIRST
  - require:
    - cmd: require_check1

require_check1: # REQUIRED STATE
 cmd.run:
  - name: echo SECOND




If the REQUIRED STATE not successful:



require_in:

* Requisites of this form( _in ) force other states to depend on the state that contains the requisite.

* The requiring states run first and then run the required state if requiring state run succcessful.

Ex:


# cat req.sls
require_check: # REQUIRING STATE
 cmd.run:
  - name: echo FIRST
  - require_in:
    - cmd: require_check1

require_check1: # REQUIRED STATE
 cmd.run:
  - name: echo SECOND






If the REQUIRING STATE not successful:


> : - )

Friday, 14 August 2015

BASH SCRIPT AND CRON FOR mysqldump PROCESS(LINUX):

This script will help to take mysql dump particularly when you want to exclude few db in server.


* kindly update the required database list on the file: db.list

With password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump --user="username" --password="password" $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Without password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Add to cron:

# vi mysql_dump_cron.sh
#!/bin/bash
#script will use for when you take db backup for selective range of db's
BACKUP=DB_BACKUP_`date +%Y-%m-%d-%H:%M`
mkdir -p /path/to/BACKUP
for i in `cat /path/to/db.list`
do mysqldump $i > /path/to/BACKUP/$i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> /path/to/BACKUP/db_filed.txt
else
echo $i Success >> /path/to/BACKUP/db_success.txt
fi
done


Daily cron:

0 0 * * * /path/to/the/script/mysql_dump_cron.sh > /dev/null 2>&1

Wednesday, 12 August 2015

How To Find My Public IP Address From Command Line:

To Find My Public IP Address From Command Line:


# host myip.opendns.com resolver1.opendns.com | grep ^myip | awk '{print $4}'

(or)

# dig myip.opendns.com @resolver1.opendns.com +short

(or)

# dig TXT o-o.myaddr.l.google.com @ns1.google.com +short

:-) !

Tuesday, 9 June 2015

How to disable domain lookup in cisco router(Translating "xxxxxx"...domain server (255.255.255.255)) ?

Lookup:

Translating "xxxxxx"...domain server (255.255.255.255)

** Simply we can aborte the domain lookup by: ctrl + shift + 6

** To disable the domain lookup [should be On config mode]: Router(config)#no ip domain lookup

** The same we can enable the domain lookup
[should be On config mode]: Router(config)#ip domain lookup

!=!=!=!=!=!=!=!

Friday, 1 May 2015

Coding attempt in PYTHON (bmi_calculator)

This is my first attempt in python coding and tried-out to create a script in python for bmi_calculator.

* create file as bmi_calculator.py
* paste the below code
* # python bmi_calculator.py


#!/usr/bin/env python
name = raw_input('Enter your Name:\t')
height = input('Enter your Height "In Centimeter":\t')
weight = input('shall we know your weight"In Kg":\t')
he = float(height) / 100 # cm to m
suwe = he * he
maa = weight / suwe
#print 'Name:', name
#print 'Height:', height
#print 'Weight:', weight
ma = round(maa)
print 'So, %s your BMI is:\t'  % name, ma
print 'Rount of value:\t', int(ma)
mx = int(ma)
print 'Your Health status is:'
if mx < 19:
        print 'Underweight'
elif mx >= 19 and mx <= 25:
        print 'Normal'
elif mx >= 25 and mx <= 30:
        print 'Overweight'
elif mx >= 30:
        print 'Too Fat, kindly start the workout right now !'
print 'Thank you !'

output:


BMI_CALCULATOR In Python3:

#!/usr/bin/python3
name = input('Enter your Name:\t')
height = input('Enter your Height "In Centimeter":\t')
weight = input('shall we know your weight"In Kg":\t')
he = float(height) / 100 # cm to m
suwe = he * he
maa = float(weight) / float(suwe)
#print 'Name:', name
#print 'Height:', height
#print 'Weight:', weight
ma = round(maa)
print ('So, %s your BMI is:\t'  % name, ma)
print ('Rount of value:\t', int(ma))
mx = int(ma)
print ('Your Health status is:')
if mx < 19:
 print ('Underweight')
elif mx >= 19 and mx <= 25:
 print ('Normal')
elif mx >= 25 and mx <= 30:
 print ('Overweight')
elif mx >= 30:
 print ('Too Fat, kindly start the workout right now !')
 print ('Thank you !')

Simple way to find the year of birth - calculator in python3:

#!/usr/bin/python3
mymsg = input('Enter your name: ')
print ('Okay, Let\'s find ' + mymsg + '\'s year of birth !' )
ga = input('Enter your age(completed age): ')
ag = ( 1330 - int(ga) + 686 )
print ("Thanks", mymsg +', '+  "Your Year of Birth: ", ag)

Saturday, 25 April 2015

shell script to gather Server information (after login):

It will shows the server information when login.

# create a file 'server_info.sh'
# copy and paste the below code.
=========================================

#!/bin/bash
wait ()
{
echo -en  "Gathering server information..."
a=1
while [ $a -le 20 ]
do
echo -ne "."
sleep .1
a=`expr $a + 1`
done
}

pause ()
{
   echo "Press [ Enter ] to continue..."
   read -p "$*"
}

raw_mem=$(cat /proc/meminfo  | grep 'MemTotal\|MemFree\|^Cached' | awk '{print $2}')
me=$(echo $raw_mem |awk '{print $1}')
tot=$((me/1024))
mef=$(echo $raw_mem |awk '{print $2}')
fre=$((mef/1024))
mec=$(echo $raw_mem |awk '{print $3}')
cac=$((mec/1024))
use=$((tot-fre))
ho=$(hostname)
os=$(cat /etc/redhat-release)
ker=$(uname -sr)
curc=$(who | awk '{print $1}'| wc -l)
lo=$(uptime| cut -f3,4,5 -d',')
wait
clear

echo -e "\nSYSTEM INFORMATION!"
echo -e "==================="
echo -e "\nOS info:" $os
echo -e "kernel name/release:" $ker
echo -e "\nMEMORY STATUS:"
echo -e "=============="
echo -e 'Total Memory:' $tot 'MB'
echo -e 'Memory In Use:' $use 'MB'
echo -e 'Free Memory:' $fre 'MB'
echo -e 'Cached Memory:' $cac 'MB'
echo -e '\n=> Hostname:' $ho
echo -e '=> Currnet users:' $curc
echo -e '=> Server' $lo '\n'
pause
clear

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

# echo "/bin/bash /path/to/server_info.sh" >> /root/.bashrc

# from next login, you can find the server_info.sh's work....



Press [ Enter ] to continue...

!!!!!!.....