Posts

Showing posts from 2015

crontab entry with date command

crontab -l */1 * * * * sh /Davinder/Scripts/disk_wrap.sh First script to just create log files:    [root@linuxhost logs]# cat /Davinder/Scripts/disk_wrap.sh #!/bin/bash sh /Disk_full.sh >/Davinder/Scripts/logs/disk_full.log_`date +%d%m%^C%H%M%S` Main script --> /Disk_full.sh   #!/bin/bash DISK_USAGE=`df -TH | grep -w "/"|awk '{print $5+0}'` #a=`echo ${DISK_USAGE%%.*}` #echo "$DISK_USAGE" a=${DISK_USAGE:0:2} #echo $a if [ $a -gt 95 ]; then                 echo "It is more than 96%..Cleaning Disk"                 echo 0 > /var/log/httpd/error_log #               sleep 10                 Disk_Check=`df -TH | grep -w "/"|awk '{print $5+0}'`                         if [ $a -gt 96 ];                                 then                                         echo "Now disk usage of "/" partition is $Disk_Check"                         fi         else                 echo "Disk usage of "

Script: Clean log file after "/" crossed 95% usage.

#!/bin/bash DISK_USAGE=`df -TH | grep -w "/"|awk '{print $5+0}'` #a=`echo ${DISK_USAGE%%.*}` #echo "$DISK_USAGE" a=${DISK_USAGE:0:2} #echo $a if [ $a -gt 95 ]; then                 echo "It is more than 96%..Cleaning Disk"                 echo 0 > /var/log/httpd/error_log #               sleep 10                 Disk_Check=`df -TH | grep -w "/"|awk '{print $5+0}'`                         if [ $a -gt 96 ];                                 then                                         echo "Now disk usage of "/" partition is $Disk_Check"                         fi         else                 echo "Disk usage of "/" partition is $DISK_USAGE"%" and below the threshold" fi OUTPUT: [root@linuxhost /]# ./Disk_full.sh Disk usage of / partition is 74% and below the threshold

mysql commands on users

mysql> select user,host from mysql.user; +---------+-----------------+ | user    | host            | +---------+-----------------+ | root    | 127.0.0.1       | | root    | linuxhost.local | | newuser | localhost       | | root    | localhost       | +---------+-----------------+ 4 rows in set (0.14 sec) mysql> show grants for 'root'@'localhost'; +----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@localhost                                                                                                              | +----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*84BB5DF4823DA319BBF86C99624479A198E6EEE9' WITH GRANT OPTION | +---------------------------------------------

Why Pay when education is free !

Why Pay when education is free ! Share on LinkedIn Share on Facebook Share on Twitter Why pay for education when it is free.. here is my list of sites that can be used for getting free training. Courses range from IT to Arts... there are some courses which give certificate of completion but have a fees attached. Good part is that they are recognized by many organizations when hiring. So pick a topic of your interest and start learning something new today : https://www.udacity.com   -  IT skills related courses https://www.khanacademy.org/  - Everyday topic on Maths, Science, Arts.. https://www.coursera.org/  - Non IT skills like Arts, Humanities, Admin etc.  https://www.edx.org/  - Courses on anything and everything https://alison.com/  - Diploma and other courses on Non IT skills Then comes the MOOC folks. Here is a short list http://online-learning.harvard.edu/courses  - Harvard http://online.stanford.edu/courses  - Standford https://onlinecourses.nptel.ac.in/exp

How to run all scripts in a directory on Linux

How to run all scripts in a directory on Linux Posted on   November 5, 2013   by   Dan Nanni 2 Comments Question:   I have a bunch of scripts in a directory. I want to automatically run all the scripts in the directory, regardless of how many these are. If you want to   run all scripts or executable binaries in a particular directory , you can use a command line utility called   run-parts . This tool can automatically discover multiple scripts or programs in a directory, and run them all. You can use   run-parts   command in the following format. $ run-parts [options] Scripts found in a directory will be run one by one in a lexically sorted order.   run-parts   will execute all the scripts whose names consist of alphanumeric letters, underscores and hyphens. For example, to run all scripts in the current directory: $ run-parts . Optionally, you can run only those scripts whose names are matched with a regular expression. For that, use "--regex" option.

python: readline() and read()

[root@mysql Scripts]# ./file1.py If we give print han1 Then output would be File is open only once Actual output should be like this so use han1.readline() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first   I am a bes If you use again han1.readline(10) then it will print next 10 character untill didnt get next line t player If you use han1.readline(15) then again print next 15 characters  I am the best p ------------------now start read()-------------------- Now use han1.read() layer I am  best player I am an best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player This will print only Blank lines han1.read(20)....  because file completly open by last command now nothing to read in file so only blank spaces...:)

Python: Open file example 1

#!/usr/bin/python han1 = open("davinder.txt","r") print "\n\n" print "If we give print han1 Then output would be", han1, "\n\n" print "File is open only once" print "Actual output should be like this so use han1.readline()", han1.readline(),"\n" print "If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first \n ", han1.readline(10) print "If you use again han1.readline(10) then it will print next 10 character untill didnt get next line", han1.readline(10) print "If you use han1.readline(15) then again print next 15 characters ", han1.readline(15) print "------------------now start read()--------------------" print "Now use han1.read()", han1.read() Output: [root@mysql Scripts]# ./file1.py If we give print han1 Then output would be File is open only once Actual output should be like this so use han1.read

Python: Simple for loop

#!/usr/bin/python import sys c = "I am a best player" a = range(1,11) print a for b in a:         print  c OUTPUT: [root@mysql Scripts]# python For.py [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player  

python: Print the table of enter value

#!/usr/bin/python import sys c = input("What Table you want to learn ") print "you have entered table of ",c a = range(1,11) print a for b in a:         print  c,"*",b,"=", b * c Output:  [root@mysql Scripts]# python for.py What Table you want to learn 4 you have entered table of  4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36 4 * 10 = 40 [root@mysql Scripts]# python for.py What Table you want to learn 6 you have entered table of  6 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54 6 * 10 = 60

IF and elif and else

#!/usr/bin/python import sys # By default argument will count script name also so I have reduced -1 for exact value arg_count = len(sys.argv) - 1 #print what I have entered in arguments" print "\nYou have entered ",arg_count, "arguments", sys.argv[1],",", sys.argv[2] # Store Argurments in variable Arg_first = sys.argv[1] print "\nType of first argument is ", type(Arg_first) # store second arg in variable Arg_Sec  =  sys.argv[2] print "\nType of second argument is", type(Arg_Sec) #By default argement will be in string type so converting in integer for mathematical a = int(Arg_first) print "\nAfter converting argument type is", type(a) b = int(Arg_Sec) print "After converting second argument type is", type(b) if a == b:         print "\nAddition of Argument 1 and Argument 2 is", a + b elif a < b:         print "\nMultiple of Arg1 and Arg2 is", a * b elif a > b:         print "\nDi

Argument Printing

#!/usr/bin/python import sys print len(sys.argv) print sys.argv print sys.argv[1] name = sys.argv[1] age =  sys.argv[2] print "My name is ",name, "and age is",age Output: [root@mysql Scripts]# python if.py davinder 35 3 ['if.py', 'davinder', '35'] davinder My name is  davinder and age is 35

arguments Printing

#!/usr/bin/python import sys print len(sys.argv) print sys.argv print sys.argv[1] Output: [root@mysql Scripts]# python if.py 3 3 3 ['if.py', '3', '3'] 3 [root@mysql Scripts]# python if.py 5 3 3 ['if.py', '5', '3'] 5 [root@mysql Scripts]# python if.py davinder singh 3 ['if.py', 'davinder', 'singh'] davinder

count arguments

#!/usr/bin/python import sys print len(sys.argv) OUTPUT: [root@mysql Scripts]# python argu.py 1 [root@mysql Scripts]# python argu.py 3 2 [root@mysql Scripts]# python argu.py 3 2 3 [root@mysql Scripts]# python argu.py 3 2 4 4 [root@mysql Scripts]# python argu.py 3 2 4 6 5 [root@mysql Scripts]# python argu.py 3 2 4 6 7 8 7

Python: declare variables and printing

#!/usr/bin/python my_name = "davinder" my_age = 35 my_designation = "Lead Architect" my_weight = 82 my_eyes = "black" my_hairs = "black" print "Let's talk about %s." % my_name print "Let's talk about %d." % my_age print "My hairs color is %s." % my_hairs OUTPUT: #./variables.py Let's talk about davinder. Let's talk about 35. My hairs color is black.  

The Cisco Three-Layered Hierarchical Model

Image
Cisco has defined a hierarchical model known as the hierarchical internetworking model. This model simplifies the task of building a reliable, scalable, and less expensive hierarchical internetwork because rather than focusing on packet construction, it focuses on the three functional areas, or layers, of your network:   Core layer : This layer is considered the backbone of the network and includes the high-end switches and high-speed cables such as fiber cables. This layer of the network does not route traffic at the LAN. In addition, no packet manipulation is done by devices in this layer. Rather, this layer is concerned with speed and ensures reliable delivery of packets.   Distribution layer : This layer includes LAN-based routers and layer 3 switches. This layer ensures that packets are properly routed between subnets and VLANs in your enterprise. This layer is also called the Workgroup layer. Access layer : This layer includes hubs and switches. This layer is also called the des

Take snapshot of KVM image

Q: How to take snapshot: A: [root@islpfdbldkvm2 ~]# qemu-img info  /home/Vms/SLES_11_SP0_PSMB_BKP2/SLES11_SP0_BKP2.img                                             image: /home/Vms/SLES_11_SP0_PSMB_BKP2/SLES11_SP0_BKP2.img file format: raw virtual size: 1.0T (1073741824000 bytes) disk size: 21G [root@islpfdbldkvm2 SLES_11_SP0_PSMB_BKP2]# qemu-img create -f qcow2 -b SLES11_SP0_BKP2.img SP0-snapshot.img Formatting 'SP0-snapshot.img', fmt=qcow2 size=1073741824000 backing_file='SLES11_SP0_BKP2.img' encryption=off cluster_size=65536 [root@islpfdbldkvm2 SLES_11_SP0_PSMB_BKP2]# qemu-img info SP0-snapshot.img image: SP0-snapshot.img file format: qcow2 virtual size: 1.0T (1073741824000 bytes) disk size: 148K cluster_size: 65536 backing file: SLES11_SP0_BKP2.img

scan lun in VIOS

$ lspv -size NAME            PVID                                SIZE(megabytes) hdisk0          00c7ed34a649c11b                    140013 hdisk1          00c7ed34fe3395ee                    140013 hdisk2          00c7ed34956f9a40                    140013 hdisk3          00c7ed3408b1659e                    140013 hdisk8          00c7ed34bd7c8966                    512000 hdisk9          00f75469f70b24ce                    20480 hdisk10         00f68d92be57434f                    30720 hdisk6          none                                139776 hdisk11         none                                144384 hdisk12         none                                102400 $ cfgdev $ lspv -size NAME            PVID                                SIZE(megabytes) hdisk0          00c7ed34a649c11b                    140013 hdisk1          00c7ed34fe3395ee                    140013 hdisk2          00c7ed34956f9a40                    140013 hdisk3          00c7ed3408b1659e                    140013 hdi

multiple gateways in one server

# cat Set_Dual_Brigde_Network.sh #!/bin/bash # http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html echo 1 T1 >> /etc/iproute2/rt_tables echo 2 T2 >> /etc/iproute2/rt_tables echo 3 T3 >> /etc/iproute2/rt_tables T1=T1 T2=T2 T3=T3 IF1=br0 IF2=br2 IF3=br3 IP1=9.12.13.15 IP2=9.12.6.50 IP3=9.10.11.35 P1=9.12.13.1 P2=9.12.6.1 P3=9.10.11.1 P1_NET=13 P2_NET=6 P3_NET=11 ip route add $P1_NET dev $IF1 src $IP1 table $T1 ip route add default via $P1 table $T1 ip route add $P2_NET dev $IF2 src $IP2 table $T2 ip route add default via $P2 table $T2 ip route add $P3_NET dev $IF3 src $IP3 table $T3 ip route add default via $P3 table $T3 ip route add $P1_NET dev $IF1 src $IP1 ip route add $P2_NET dev $IF2 src $IP2 ip route add $P3_NET dev $IF3 src $IP3 ip rule add from $IP1 table $T1 ip rule add from $IP2 table $T2 ip rule add from $IP3 table $T3

powerKVM commands

pokgsa.ibm.com/projects/p/pkvm-updates/devel/IBM/powerkvm-devel.repo [powerkvm-updates-devel] name=powerkvm-updates-devel baseurl=http://pokgsa.ibm.com/projects/p/pkvm-updates/devel/IBM/$ibmver/updates enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ibm_powerkvm-$ibmver [powerkvm-debuginfo-devel] name=powerkvm-debuginfo-devel baseurl=http://pokgsa.ibm.com/projects/p/pkvm-updates/devel/IBM/$ibmver/debuginfo enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ibm_powerkvm-$ibmver Kernel: http://ltcphx.austin.ibm.com/isos/frobisher/PowerKVM/releases/2.1.1/0.9.1/os/ppc/ppc64/vmlinuz Initrd: http://ltcphx.austin.ibm.com/isos/frobisher/PowerKVM/releases/2.1.1/0.9.1/os/ppc/ppc64/initrd.img Device tree: Boot arguments: root=live:http://ltcphx.austin.ibm.com/isos/frobisher/PowerKVM/releases/2.1.1/0.9.1/os/LiveOS/squashfs.img repo=http://ltcphx.austin.ibm.com/isos/frobisher/PowerKVM/releases/2.1.1/0.9.1/os/packages rd.dm=0 rd.md=0 console=hvc0 console=tty0 Kernel: ht