Hello,
I wrote a simple script, that basically wait for a *.dat-file in a certain folder, which is always a zipped file and extracts it.
It worked before and i changed nothing in the script, but since last week i have the problem, that it doesnt extract files containing a space. How do i make it also extract files containing spaces again?
If found something with
IFS="$IFS"
IFS=$'\n'
but it doesnt seem to work.
and another problem i have is, i am looking for pictures in the extracted files, but if no .png or .jpg files are found it still opens the literal ".jpg" and ".png"-files in sublime, how can i make it, that if no pictures are found, it doesnt open that file or sets "${BILDER_JPG[@]}" "${BILDER_PNG[@]}" to "" ?
#!/bin/bash
#for handling spaces in filenames
IFS="$IFS"
IFS=$'\n'
DOWNLOAD_DIR=~/Downloads/neu
DSM=dsm
while true;
do
for file in $(ls $DOWNLOAD_DIR/*.dat)
do
if [ -f $file 0 ]
then
DATE=$(date +"%H_%M_%S")
unzip -q {$file} -d $DOWNLOAD_DIR/debug_$DATE
if [ $? -eq 0 ] # remove if successfully extracted
then
mv $file $DOWNLOAD_DIR/debug_$DATE
#ln -s $DOWNLOAD_DIR/debug_$DATE/dsm/var/log/messages $DOWNLOAD_DIR/debug_$DATE/messages
echo $file " erfolgreich entpackt."
echo "DOWNLOAD_DIR: " $DOWNLOAD_DIR
if [ -f $DOWNLOAD_DIR/debug_$DATE/packages.list ]
then DSM=""
fi
DEBUG_DIR=$DOWNLOAD_DIR/debug_$DATE
if [ -f $DOWNLOAD_DIR/debug_$DATE/$DSM/proc/mdstat ]
then MDSTAT=$DOWNLOAD_DIR/debug_$DATE/$DSM/proc/mdstat
fi
if [ -f $DOWNLOAD_DIR/debug_$DATE/$DSM/result/df.result ]
then DF=$DOWNLOAD_DIR/debug_$DATE/$DSM/result/df.result
fi
if [ -f $DOWNLOAD_DIR/debug_$DATE/$DSM/result/ifconfig.result ]
then IFCONFIG=$DOWNLOAD_DIR/debug_$DATE/$DSM/result/ifconfig.result
fi
for file in $(ls $DOWNLOAD_DIR/debug_$DATE/$DSM/result/smart*.result)
do
echo $file >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
echo " " >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
awk '/SMART Error Log Version: 1/{f=1;next} /Selective self-test flags/{f=0} f' $file >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
echo " " >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
echo " " >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
echo " " >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
echo " " >> $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
$DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
done
declare -a SMART_FILES
SMART_FILES=( "${DOWNLOAD_DIR}/debug_${DATE}/${DSM}/result/smart"*.result )
if [ -f $DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result ]
then SMART_GREP=$DOWNLOAD_DIR/debug_$DATE/$DSM/smart_grep.result
fi
if [ -f $DOWNLOAD_DIR/debug_$DATE/$DSM/var/log/messages ]
then MESSAGES=$DOWNLOAD_DIR/debug_$DATE/$DSM/var/log/messages
fi
declare -a BILDER_JPG
for file in "${DOWNLOAD_DIR}/debug_${DATE}/"*.jpg; do
[[ -f "${file}" ]] # Do something with this
BILDER_JPG+=( "${file}" )
done
alt: BILDER_JPG=( "${DOWNLOAD_DIR}/debug_${DATE}/"*.jpg )
declare -a BILDER_PNG
for file in "${DOWNLOAD_DIR}/debug_${DATE}/"*.png; do
[[ -f "${file}" ]] # Do something with this
BILDER_PNG+=( "${file}" )
done
#echo "JPG: " $BILDER_JPG
#echo "PNG: " $BILDER_PNG
#alt: BILDER_PNG=( "${DOWNLOAD_DIR}/debug_${DATE}/"*.png )
#echo "BILDER_PNG Inhalt: " $BILDER_PNG
subl $DEBUG_DIR ${SMART_FILES[@]} $SMART_GREP $MDSTAT $DF $IFCONFIG $MESSAGES:100000 "${BILDER_JPG[@]}" "${BILDER_PNG[@]}"
# ${SMART_FILES[@]} "${BILDER_JPG[@]}" "${BILDER_PNG[@]}"
else
mkdir $DOWNLOAD_DIR/kapott
mv $file $DOWNLOAD_DIR/kapott/debug_$DATE.dat
echo $file "konnte nicht entpackt werden."
zenity --error --text="Debug konnte nicht entpackt werden\!" --title="Achtung!"
fi
fi
done
sleep 5
done
IFS="$OIFS"