File moving shell script according to unix time stamp
change the variables given inside comments. TimeValue should be in HH:MM:SS time format
#!/bin/bash
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++Variables++++++++++++++++++++++++++++++++++++
Source=/home/nipuna/first/
Destination=/home/nipuna/second/
TimeValue=00:05:00
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#Getting date to variable
CheckTime=`date cut -d" " -f4`
#Split Time Value
tHour=`echo $TimeValue cut -f1 -d:`
tMin=`echo $TimeValue cut -f2 -d:`
tSec=`echo $TimeValue cut -f3 -d:`
#Split Date Value
cHour=`echo $CheckTime cut -f1 -d:`
cMin=`echo $CheckTime cut -f2 -d:`
cSec=`echo $CheckTime cut -f3 -d:`
#Sub. by TimeValue
cHour=`expr $cHour - $tHour`
cMin=`expr $cMin - $tMin`
cSec=`expr $cSec - $tSec`
#echo $cHour "." $cMin "." $cSec
#getting file list with time
File_List=`ls --full-time --time-style=full-iso -t $Source awk '{print $7 "%" $9}'`
for i in $File_List;
do
if [ '%' != $i ]; then #remove bulk values
#split file time values
fHour=`echo $i cut -f1 -d:`
fMin=`echo $i cut -f2 -d:`
fSec=`echo $i cut -f3 -d: cut -f1 -d.`
if [ $cHour -gt 0 ]; then
tHour=`expr $fHour - $cHour`
tMin=`expr $fMin - $cMin`
tSec=`expr $fSec - $cSec`
else
tHour=`expr $cHour - $fHour`
tMin=`expr $cMin - $fMin`
tSec=`expr $cSec - $fSec`
fi
if [ $tHour -lt 0 ]; then
fileName=`echo $i cut -f2 -d%`
mv $Source/$fileName $Destination
echo "$fileName moved"
fi
fi
done
change the variables given inside comments. TimeValue should be in HH:MM:SS time format
#!/bin/bash
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++Variables++++++++++++++++++++++++++++++++++++
Source=/home/nipuna/first/
Destination=/home/nipuna/second/
TimeValue=00:05:00
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#Getting date to variable
CheckTime=`date cut -d" " -f4`
#Split Time Value
tHour=`echo $TimeValue cut -f1 -d:`
tMin=`echo $TimeValue cut -f2 -d:`
tSec=`echo $TimeValue cut -f3 -d:`
#Split Date Value
cHour=`echo $CheckTime cut -f1 -d:`
cMin=`echo $CheckTime cut -f2 -d:`
cSec=`echo $CheckTime cut -f3 -d:`
#Sub. by TimeValue
cHour=`expr $cHour - $tHour`
cMin=`expr $cMin - $tMin`
cSec=`expr $cSec - $tSec`
#echo $cHour "." $cMin "." $cSec
#getting file list with time
File_List=`ls --full-time --time-style=full-iso -t $Source awk '{print $7 "%" $9}'`
for i in $File_List;
do
if [ '%' != $i ]; then #remove bulk values
#split file time values
fHour=`echo $i cut -f1 -d:`
fMin=`echo $i cut -f2 -d:`
fSec=`echo $i cut -f3 -d: cut -f1 -d.`
if [ $cHour -gt 0 ]; then
tHour=`expr $fHour - $cHour`
tMin=`expr $fMin - $cMin`
tSec=`expr $fSec - $cSec`
else
tHour=`expr $cHour - $fHour`
tMin=`expr $cMin - $fMin`
tSec=`expr $cSec - $fSec`
fi
if [ $tHour -lt 0 ]; then
fileName=`echo $i cut -f2 -d%`
mv $Source/$fileName $Destination
echo "$fileName moved"
fi
fi
done
Comments
Post a Comment