I am writing a small script to upload the files to remote ssh server and on the remote ssh server I will have almost 2 TB
of Space available.
I need to check within the shell script if the Space is around 1.5 TB
full than sleep the script
and **start the script again**
once its goes back it goes back to 1TB
here is my part of the code which needs to run the logic for checking the directory size and then put it into the if else statements
SIZE="$(ssh archiveupload@REMOTESERVER-IP "du -s")"
LIMIT="1.5TB"
if [ $SIZE -gt $LIMIT ];
then
sleep 4h
elif
continue ;
fi
UPDATE SCRIPT:
if [ ! -f /home/user/Tupload/upload-lock ]; then
touch /home/user/Tupload/upload-lock
###Define the File in unix style#############
filename="/home/user/Tupload/20186.txt"
####starting of the while loop.###########
LIMIT='1500000000'
while read line;
do
name="${line%$'\r'}"
SIZE="$(ssh -n USER@REMOTEIP"df /var/www/Upload/" | awk 'NR > 1 {print $4; exit}')"
if [[ $SIZE -gt $LIMIT ]]
then
YEAR=$(echo $name | cut -c 1-4) #####define the Year from the read line ####
MONTH=$(echo $name | cut -c 5-6) #####Define the Month from the read line####
DAY=$(echo $name | cut -c 7-8) #####Define the DAY from the read line####
YM=${YEAR}-${MONTH} ####define the Year and Month######
april="2017-04"
may="2017-05"
june="2017-06"
march="2017-03"
######if else statement ######
if [ "$april" = "$YM" ]; then
cd /mnt/smxfxml/$YEAR/April/
elif [ "$may" = "$YM" ]; then
cd /mnt/smxfxml/$YEAR/May/
elif [ "$june" = "$YM" ]; then
cd /mnt/smxfxml/$YEAR/June/
elif [ "$march" = "$YM" ]; then
cd /mnt/smxfxml/$YEAR/March/
else
cd /mnt/smxfxml/$YEAR/$YM/
fi
ssh USER@REMOTEIP"mkdir $YEAR/$MONTH/$DAY/$name/" < /dev/null
scp $name.mxf USER@REMOTEIP:$YEAR/$MONTH/$DAY/$name/
cd /mnt/smxfxml/XML/$YEAR/$YM/
scp $name.xml USER@REMOTEIP:$YEAR/$MONTH/$DAY/$name/
else
echo 'Not enough space.'; sleep 4h
fi
done <"$filename"
rm -rf /home/user/Tupload/upload-lock
exit 0
else
sleep 0
fi
exit 0
ssh -n ...
is equivalent ofssh ... < /dev/null
, reference: askubuntu.com/a/979457/566421