mercredi 1 avril 2015

Combing several subqueries in IF statement

Current directory contains new logs that keep coming.

/tmp/logstash/ dir contains logs to which I will be comparing new ones


Conditions:

If the new log has the same name and the size that already exists in /tmp/logstash, I should get 'identical file already exists' msg.

Otherwise the script will move the new log to /tmp/logstash/.


Note, that if name is same but size is different, the script should still move new file to tmp/logstash/


My script is as follows and it's not working properly with with combining 'then && if', can you please help to fix it?



for file in *.log; do
new_filesize=$(du -b "$file" | cut -f 1)
if [[ -e /tmp/logstash/"$file" ]]
then
old_filesize=$(du -b /tmp/logstash/"$file" | cut -f 1) &&
if [[ "$new_filesize"="$old_filesize" ]]; then
echo "The file already exists"
fi
else mv $file /tmp/logstash
fi
done

Aucun commentaire:

Enregistrer un commentaire