Anlık haberler

Kullanıcı blogları

Dizi,Film,Anime

Programlama

Bir Komutun Hangi RPM Paketinde Olduğunu Bulma

Bir komutun hangi rpm paketi tarafından sağlandığını bulmak bazen uğraştırıcı olabiliyor. Aşağıdaki bash script koduyla kolayca hangi konutun hangi rpm paketi tarafından sağlandığını kolayca bulabilirsiniz. Aşağıdaki bash script kodunu whichrpm diye bir dosyaya yapıştırın ve çalıştırma izni verin.
Script kullanımı ekrana yazdırmak icin.
whichrpm -h
Eğer komut o bilgisayarda çalışıyorsa. Örnegin echo komutunun hangi rpm paketi tarafından sağlandığını bulalım.
whichrpm -c echo
Eğer komut o bilgisayarda çalışımıyorsa. Örneğin CentOS 6.3 iso'sunu extract ederek echo komutunun hangi rpm paketi tarafından sağlandığını bulalım.
whichrpm -c echo -d /home/dummy/extracted_centos_iso/Packages

#!/bin/sh ## coded by Mehmet Kozan at 11.04.2014 ## http://www.mehmetkozan.com ######################################################### ## GLOBALS VARS ######################################### ######################################################### TRUE=0 FALSE=1 NULL="/dev/null"; exec 3> $NULL; TTY=`tty`; [ "$?" -ne "0" ] && TTY="$NULL"; [ ! "$TTY" ] && TTY="$NULL"; exec 4> $TTY; ########################################################### ## GLOBAL FUNCTIONS ####################################### ########################################################### #print only console, not stdout or stderr ptty() { echo -ne "$@" 1>&4; [ "$TTY" == "$NULL" ] && return $FALSE; return $TRUE; } ## print stdout pout() { ptty "\t>> printing to stdout=$@"; RETVAL="$?"; ptty " - \""; echo -ne "$@"; ptty "\"\n"; return $RETVAL; } ## print header phead() { ptty "\n## $@ ####\n"; return $?;} ## print info pinf() { ptty "\t## $@\n"; return $?; } ##print error perr() { ptty "\t!! $@\n" 1>&2; return $?; } fixdir() { MYFULLDIR="$(readlink -nf "$1")";MYDIR="$(dirname $MYFULLDIR)";MYNAME="$(basename $MYFULLDIR)";cd $MYDIR;} isroot() { [ "$EUID" -ne "0" ] && { perr "This script must be run as root..."; exit $FALSE;};} ## call global functions ## ##isroot fixdir "$0" ########################################################### ## USAGE ################################################## ########################################################### usage() { cat << EOFILE USAGE: $MYNAME [-v] -c command_name [-d rpm_directory] EXAMPLE USAGE: $MYNAME -c echo $MYNAME -v -c echo $MYNAME -v -c echo -d /home/dummy/extracted_centos_iso/Packages $MYNAME -c echo -d /home/dummy/extracted_centos_iso/Packages OPTIONS: -v: verbose, echo extra outputs [optional] -c: command -d: directory which contains rpm [optional] EOFILE exit $FALSE } #end usage() ########################################################### ## DEFAULT ARS ############################################ ########################################################### MIN_MAIN_ARGS_COUNT="0" IS_VERBOSE=false ########################################################### ## FUNCTIONS ############################################## ########################################################### ## if -v paremeter exist, verbosely print all output iv() { $IS_VERBOSE && return $TRUE || return $FALSE; } #end iv(), is_verbose ########################################################### ## SET OPTIONS ARGS ####################################### ########################################################### while getopts "vc:d:" opt; do case "${opt}" in v) IS_VERBOSE=true ;; c) COMMAND_NAME=${OPTARG} ;; d) RPM_DIR=${OPTARG} ;; *) usage ;; esac done ########################################################### ## SET MAIN ARGS ########################################## ########################################################### shift $((OPTIND-1)) MAIN_ARGS="$@" ########################################################### ## CHECK REQUIRE ARGUMENTS ################################ ########################################################### ( [ -z "$COMMAND_NAME" ] ) && usage ( [ $# -lt $MIN_MAIN_ARGS_COUNT ] ) && usage ########################################################### ## MAIN ################################################### ########################################################### phead "checking command name" COMMAND_BIN_PATH=`which $COMMAND_NAME 2>$NULL` if [ "$?" != "0" ];then perr "command name \""$COMMAND_NAME"\" not found"; SEARCH_TEXT="^/bin/$COMMAND_NAME|^/usr/bin/$COMMAND_NAME|^/usr/sbin/$COMMAND_NAME" pinf "assuming search text is, \"$SEARCH_TEXT\"" else COMMAND_BIN_PATH=`readlink -nf "$COMMAND_BIN_PATH"` if [ "$?" == "0" ];then SEARCH_TEXT="^$COMMAND_BIN_PATH" else SEARCH_TEXT="^/bin/$COMMAND_NAME|^/usr/bin/$COMMAND_NAME|^/usr/sbin/$COMMAND_NAME" perr "readlink error,ssuming search text is, \"$SEARCH_TEXT\"" fi fi pinf "SEARCH_TEXT=$SEARCH_TEXT" if [ "$RPM_DIR" ];then if [ ! -d "$RPM_DIR" ];then perr "rpm_dir=$RPM_DIR not a directory. exiting.." exit $FALSE fi phead "searching in directory" cd "$RPM_DIR" for RPM_FILE in `ls *.rpm`; do if rpm -qpl "$RPM_FILE" | grep -qE "^${SEARCH_TEXT}";then RPM="$RPM_FILE" pinf "RPM=$RPM" break fi done else phead "searching in installed rpms" ## iterate installed rpms for INSTALLED_RPM in `rpm -qa`; do if rpm -ql "$INSTALLED_RPM" | grep -qE "${SEARCH_TEXT}";then RPM="$INSTALLED_RPM" pinf "RPM=$INSTALLED_RPM" break fi done fi if [ "$RPM" ];then pinf "rpm contains \"${COMMAND_NAME}\" executable=$RPM"; pout $RPM; exit $TRUE else perr "rpm contains \"${COMMAND_NAME}\" executable not found" exit $FALSE ```![Description](![Description](![Description](Link "Title") "Title") "Title")

daha fazla oku
Dahili hata.

Ups! Bir şeyler ters gitti sanki!