I created a script here and the script is all about checking the disk space if the disk space had enough space then it will download the file needed after that it will extract the file 5 times and it must not extract the last tar.gz
file . But when I executed the script I got a problem here. For the extract side it will just extract 1 time but I already out it 5 times.
#!/bin/bash
outout=$(df -h)
file=$(awk -F = '{print $2}' config.txt)
filename=$(echo "$bundle" | awk -F / '{print $11}')
diskspace=$(df -h /var/ | sed '1d' | awk '{print $5}' | cut -d'%' -f1)
allowed=10
address=$(awk -F = '{print $2}' newconfig.txt)
if [ "${diskspace}" -gt "${allowed}" ]; then
# cd "/var/"
wget $bundle
else
echo "Not enough space to download the bundle"
echo $output
exit
fi
i=0
for tarfile in *.tar.gz
do
$(($i++))
[ $i = 5 ] && break
tar -xf "$tarfile"
done
For the config.txt
https://www.google.com.ph/files.tar.gz
files.tar.gz is composed of 5 tar inside
files1.tar.gz -> files2.tar.gz - > files3.tar.gz -> files4.tar.gz - > files5.tar.gz
What should I do to extract it five times until files5.tar.gz will display and it must not be extracted.
Help is greatly appreciated.
Since I couldn't figure out the exact code you wan't, I would give a example code how to use while
loop instead
i=0
tar xf files.tar.gz
while [ $i -lt 4 ];do
((i++))
tar xf files${i}.tar.gz
done
Or use for
to do the same thing.
for i in "" {1..4};do
tar xf files${i}.tar.gz
done
These code executes following command
tar xf files.tar.gz
tar xf files1.tar.gz
tar xf files2.tar.gz
tar xf files3.tar.gz
tar xf files4.tar.gz
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.