Absolute path md5sum

1
#!/bin/bash

comprobacion ()   
{  
        fichero=$1;  
        #La variable a almacena el valor actual del checksum  
        a=$(ls -p $fichero | grep -v / | grep -v Script_Md| xargs md5sum);  
        #La variable  b almacena el contenido del fichero listamd5sum  
        b=$(cat $HOME/MD/ocupacion);  
        echo  -e  "\nChecksums actuales:\n"  
        echo "$a";  
        echo  -e "\nChecksums orginales:\n"  
        echo "$b";  
        if [ "$a" = "$b" ]; then #Compara el contenido de las variables a y b  
                echo -e  "\n--------------------------------------------------------------"  
                echo "| El contenido de los archivos del directorio no ha cambiado |"  
                echo "--------------------------------------------------------------"  
        else   
                echo -e "\n-------------------------------------------------------

    ----"  
                    echo "| El contenido de los archivos del directorio ha cambiado |"  
                    echo "-----------------------------------------------------------"       
            fi  
    }  

    fichero="$1";  
    if [ -e "$HOME/MD/ocupacion" ]; then  
            if [ -z "$fichero" ]; then  
                    echo "¡Directorio vacío!"  
            elif [ -e "$fichero" ]; then  
                    comprobacion $fichero #Llamada a la funcion comprobacion  
            else   
                    echo "¡El directorio no existe"  
            fi        
    else  
            if [ -z "$fichero" ]; then  
                    echo "¡Directorio vacío!"  
            elif [ -e "$fichero" ]; then  
                    #Se excluyen aquellos ficheros que son directorios, tambien el Script_Md y se calcula el checksum de los restantes  
                    ls -p "$fichero" | grep -v / | grep -v "Script_Md" | xargs md5sum >$HOME/MD/ocupacion  
            else   
                    echo "¡El directorio no existe"  
            fi  
    fi

The problem is when I initialize the variable to in the check function. The argument that the script receives is the absolute path of a directory. Now, if the directory that happened to my current pwd does not give me any problem, it occurs when, for example: My pwd is $ HOME, I pass as argument the / etc directory, in the execution of the script the following is output:

Can not find the files, md5sum does not find them, since they are not listed with absolute path. How can I do so that ls -p $fichero | grep -v / | grep -v Script_Md is listed with the absolute path of the files?

    
asked by ignacio aranguren 08.05.2018 в 16:49
source

1 answer

1

To leave the question as answered, I clarify my comment here:

xargs allows, through placeholders , to complete the parameters that will be passed to the command to call:

xargs -i{} md5sum ${fichero}/{}

In this way, the md5sum command receives as a parameter the concatenation of the route, contained in the variable fichero , and the name of the file.

    
answered by 08.05.2018 / 17:47
source