You are not logged in.
Pages: 1
Hello!
Here is my script that should search for files of a certain mime type. It finding but cannot show that they are equal even if echo shows that they are equal in output. Is it any invisible symbols for output that must be removed before comparing?
#!/bin/bash
DESTINATION='/tmp'
FTYP='XX'"image"
STYP=""
#STYP="jpeg"
if [ 'XX'"$1" != 'XX' ];then
if [ 'XX'"$STYP" != "XX" ];then
echo searching with a subtype without cutting > /dev/null
GTawk='XX'"$( xdg-mime query filetype "$1" | awk -F'/' '{print $1 $2}' )"
#GTsed='XX'"$( xdg-mime query filetype "$1" | sed 's/\///m' )"
else
#cutting everything after the '/' symbol
GTawk='XX'$(xdg-mime query filetype "$1" | awk -F'/' '{print $1 }' )
#GTsed='XX'$(xdg-mime query filetype "$1" | sed 's/\/[^,]*$//' )
fi
else
echo command line is empty
fi
if [ "$FTYP$STYP" != "$GTawk" ];then
echo The $1 file is not what we need:$FTYP$STYP'|'$GTawk: > /dev/null
echo $(xdg-mime query filetype "$1") > /dev/null
else
#Actions if found
echo found $(echo $FTYP | sed 's/^XX//m' ) in $( echo $GTawk| sed 's/^XX//m' ) > /dev/null
if [ -d "/tmp" ]; then
echo $(xdg-mime query filetype "$1") ;
cp -v "$1" /tmp
else
echo The destination doesn't exist, cannot do any action';
fi
fi
#log details in the file
#FileSize="$(du /tmp/found-mime-types-details.log -h | awk '{print $1}' | awk -F'M' '{print $1}')";
#This will limit the size of the log file by 20M
if [ "XX" == "XX"$(du /tmp/found-mime-types-details.log -h | awk '{print $1}' | awk -F'M' '{print $1}' | grep "M"$ | sed 's/K//m' | sed 's/B//m') ];
then
FileSize=0;
fi
if [ "$FileSize" -gt "1" ]; then
echo The Log file "/tmp/found-mime-types-details.log" is too big;
#rm /tmp/found-mime-types-details.log
else
#Creating a log file
echo "$1" '|' $GTawk >> /tmp/found-mime-types-details.log ;
fi
The script without safety checks:
#!/bin/bash
FullNameOfTheMime="image/jpeg"
MergedCMD="$( xdg-mime query filetype "$1" | sed 's/\///m' | awk -F';' '{print $1}')"
MergedFN="$( echo $FullNameOfTheMime | sed 's/\///m' )"
#echo "$MergedCMD";
if [ "$MergedCMD" == "$MergedFN" ];
then echo The file $1 found ;
fi;
"GTawk" does same as "GTsed", I added both just for have one more alternativ for the same jobb. But still the same problem, it might be any in the begin or end of the string.
The script is made for the file recovery with "find * -type f -exec ./img-recovry.sh "{}" \;"
I have edited my post and extended the script funtionality.
Last edited by Andy_Crowd (2014-07-01 17:16:41)
Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.
Offline
Pages: 1