Monday, February 27, 2012

RHEL 5 yum: Get repo package was installed from

If you need to get the source (repo) that a package was installed from:


1) yum -y install yum-utils 

2) sudo repoquery --repoid=<reponame> -a |xargs sudo yum list installed| egrep -i <packagename>


Also found:

Available:
yum --disablerepo=* --enablerepo=<repo_name> list | grep -v "installed" | grep <package_name>

Installed:
yum --disablerepo=* --enablerepo=<repo_name> list | grep "installed" | grep <package_name>

Thursday, February 16, 2012

RHEL: Identify if you are on a virtual machine (vm)

So you need to tell if you are working on a server that is a virtual machine or on physical hardware? This is for RedHat (RHEL), but may work on other *nix flavors...


cat /sys/class/dmi/id/product_name

or

/usr/sbin/virt-what

or

If you suspect that it may be a vmware vm, you can search for vmware tools.  Make sure path is set correctly, and:

vm<tab>

Tuesday, February 14, 2012

linux:shell Loop on a space delimited varialble


var="string with spaces"

# note that $var must NOT be quoted here!
for X in $var
do
    echo "$X"
done

Linux:shell see if arg1 has been provided

An easy way to tell if arg1 has been given when user called the script:

# Note the quotes around $1

if [ -z "$1" ]; then
    usage
else
    do-something
fi

Tuesday, February 7, 2012

Convert epoch time to date/time format

date -d @<epoch_time>

Example: date -d @1328608176
Gives: Tue Feb  7 04:49:36 EST 2012