@Gutemine
TANKS for reply, but still wrong value returned
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
root@Dream8k_M3:~#
root@Dream8k_M3:~# df -h /media/cf/movie/
Filesystem Size Used Available Use% Mounted on
/dev/sdb1 14.8G 1.7G 13.1G 12% /autofs/e5d8b110-43d4-4b58-8bfa-f79be6d91a69
root@Dream8k_M3:~#
root@Dream8k_M3:~# echo `df -h /media/cf/movie/ | grep % | grep -v Files| awk {'print $3'}`
1.7G
root@Dream8k_M3:~#
root@Dream8k_M3:~# df -h /media/hdd/movie/
Filesystem Size Used Available Use% Mounted on
/dev/disk/by-uuid/0939759a-4059-4198-bb55-8636e29a4185
465.7G 428.9G 36.8G 92% /media/hdd
root@Dream8k_M3:~#
root@Dream8k_M3:~# echo `df -h /media/hdd/movie/ | grep % | grep -v Files| awk {'print $3'}`
36.8G
root@Dream8k_M3:~#
|
currently have fixed for self by create inside function in the script
for storages which cant have 2TB and more
|
Source code
|
1
2
3
4
5
6
7
|
CheckSpaceOnSrc () {
SrcInfo=`df $SrcDir| tail -1`
case "$DstInfo" in
/*) SrcFreeSpace=`echo $SrcInfo| awk {'print $4'}`;;
*) SrcFreeSpace=`echo $SrcInfo| awk {'print $3'}`;;
esac
}
|
but for bigger storages same way just check before TB
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
CheckSpaceOnDest () {
SpaceEnough=0
DstInfo=`df -h $DstDir| tail -1`
case "$DstInfo" in
/*) if [ `echo $DstInfo| awk {'print $4'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
[ `df $DstDir| tail -1| awk {'print $4'}` -gt $(($fSize / 1024)) ]; then
SpaceEnough=1
fi
;;
*) if [ `echo $DstInfo| awk {'print $3'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
[ `df $DstDir| tail -1| awk {'print $3'}` -gt $(($fSize / 1024)) ]; then
SpaceEnough=1
fi
;;
esac
}
|
to able make all easier i miss some
sed @&^#$ to remove first word only when it begins with /
then
awk {'print $3'} will work for any source
full code of
/usr/script/move_recordings_from_CF.sh
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/bin/sh
#
# MartiniB #
#
SrcDir="/media/cf/movie/"
#DstDir="/media/net/bigdisk/movie/"
DstDir="/media/hdd/movie/"
CfFreeSpaceIsEnough=4000000 # ~4Gb
CheckSpaceOnDest () {
SpaceEnough=0
DstInfo=`df -h $DstDir| tail -1`
case "$DstInfo" in
/*) if [ `echo $DstInfo| awk {'print $4'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
[ `df $DstDir| tail -1| awk {'print $4'}` -gt $(($fSize / 1024)) ]; then
SpaceEnough=1
fi
;;
*) if [ `echo $DstInfo| awk {'print $3'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
[ `df $DstDir| tail -1| awk {'print $3'}` -gt $(($fSize / 1024)) ]; then
SpaceEnough=1
fi
;;
esac
}
CheckSpaceOnSrc () {
SrcInfo=`df $SrcDir| tail -1`
case "$DstInfo" in
/*) SrcFreeSpace=`echo $SrcInfo| awk {'print $4'}`;;
*) SrcFreeSpace=`echo $SrcInfo| awk {'print $3'}`;;
esac
}
ExitIF () {
# if night-time and free space on flash is enough
[ `date +%H` -le 08 ] && CheckSpaceOnSrc && [ "$SrcFreeSpace" -ge "$CfFreeSpaceIsEnough" ] && exit
}
ExitIF
for i in "$SrcDir"*.ts; do
if [ -e "$i" ]; then
echo "$i"
fName=${i##*/}
fName0=${fName%.ts}
fSize=`ls -l "$i"| awk {'print $5'}`
if [ ! $fSize = "0" ] && sleep 10 && [ $fSize = `ls -l "$i"| awk {'print $5'}` ]; then
CheckSpaceOnDest
if [ "$SpaceEnough" = "1" ]; then
echo "cp $SrcDir$fName0"
cp "$SrcDir$fName0"* "$DstDir"
[ $fSize = `ls -l "$SrcDir$fName0".ts| awk {'print $5'}` ] && rm -f "$SrcDir$fName0"*
fi
fi
fi
ExitIF
done
|