Created
September 26, 2020 18:39
-
-
Save kunthar/9c7d2c9d8fc88ff39a0e0126b41674e3 to your computer and use it in GitHub Desktop.
move files periodically from one directory to another in SAME server. uses cron facility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIRECTORY="/home/lmsadmin/videos" | |
FILES=$DIRECTORY/* | |
if [ -d "$DIRECTORY" ]; then | |
cd $DIRECTORY | |
shopt -s nullglob dotglob # To include hidden files | |
files=($DIRECTORY/*) | |
if [ ${#files[@]} -gt 0 ]; then | |
echo "dir is not empty, we can proceed. operation time : $(date +'%F-%H-%M')" | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
for f in $FILES | |
do | |
echo "files list" | |
echo `basename "$f"` | |
let count=count+1 | |
done | |
echo "total files: " | |
echo "Count: $count" | |
# restore $IFS | |
IFS=$SAVEIFS | |
/bin/chown www-data:www-data $DIRECTORY/* | |
/bin/chmod 777 $DIRECTORY/* | |
/bin/mv -n * /var/www/moodledata/repository/videos/ | |
else | |
echo "dir exist but no files in it, passing. operation time: $(date +'%F-%H-%M')" | |
fi | |
fi | |
# chmod +x move-files.sh | |
# after this, create cron | |
# i use ubuntu 18! | |
#crontab -e | |
# */10 * * * * /usr/local/bin/move-files.sh > 2>&1 | /usr/bin/logger -t TRANSFER | |
# all logs will be in syslog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
every 10 minutes check the directory and move the files.