Skip to content

Instantly share code, notes, and snippets.

@kunthar
Created September 26, 2020 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunthar/9c7d2c9d8fc88ff39a0e0126b41674e3 to your computer and use it in GitHub Desktop.
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.
#!/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
@kunthar
Copy link
Author

kunthar commented Sep 26, 2020

every 10 minutes check the directory and move the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment