Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Friday, October 21, 2016

Oracle Linux - Checking installed package

In some cases you want to verify if a package is installed on your Oracle Linux instance within a bash script. You query what is installed by using the "list installed" option for the yum command. However, this is giving you a more human readable result and not something that works easy in a the flow of a script. In essence you would like to have a boolean value returned to tell you if a package is installed or not on your Oracle Linux instance.

The below code example is a bash script that will exactly do so. Within the example you see the packageInstalled function which takes a variable for the package name you are looking for. The result will be true or false.

#!/bin/bash

function packageInstalled () {
     numberOfPackages=`yum list installed | grep $1 | wc -l`
     if [ "$numberOfPackages" -gt "0" ];
       then
           echo "true"
     else
         echo "false"
     fi
}

packageInstalled wget

In the example we are checking the installation of the wget package. You can change wget for whatever you need to be sure is installed. Using this building block function can help you to write a more complex script for installing packages when needed. 

Monday, March 28, 2011

Linux, check interface status

In some cases you might want to check the status of your network interfaces from a script. In a "normal" situation you can just run a ifconfig command and look if your interface is up or down however when you want to do this automated from within a script you do not want the complete output of ifconfig. You might just want a simple "up" or a simple "down" string returned. If you for example want to use this within a custom check in Nagios or Oracle Enterprise Manager.

You have some options, in the example below I will provide a "up" or a "down" string based upon the status of the interface. However you might also go for a even more simplistic way by returning a zero or one value. the script is based upon the fact that you will provide a parameter with the interface name, for example eth0 or en0. in case you provide a interface name that is none existing get a error message something like "ifconfig: interface eth0 does not exist". You can use the standard option to suppress this error message by using the default way to suppers stderr message by adding a "2> /dev/null" at the end of your script.


#!/bin/bash

IFCONFIG="/sbin/ifconfig $1"

ISIT=`$IFCONFIG | grep "UP" | wc -l`;

if test $ISIT -gt 0;
then
echo "up";
else
echo "down";
fi


Tuesday, November 27, 2007

Oracle and Python

Oracle published today a introduction paper to Oracle and Python in combination with TurboGears. Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code.

TurboGears can be seen as a development platform for database driven Python web applications and it includes the best practice code peaces which can be reused in a quick and easy way by a developer who is building a webapp with this platform. So now Oracle is adding best practice python code to this project so it will be easy for a developer to connect it to a oracle database. Also some great AJAX code can be found in TurboGears ready for you to use without writing to much code yourself.

If you like to have a quick introduction to TurboGears you view a very good video tutorial on the TurboGears website.