Created
February 23, 2012 21:02
-
-
Save kappa7194/1895037 to your computer and use it in GitHub Desktop.
The script to monitor a folder for uploaded file and their compression.
This file contains 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 | |
# Use the newline character | |
# as the field separator. | |
IFS=$'\n' | |
# The folder to watch. | |
dir="/home/bbf/upload/" | |
# Get the folder's content, recurively. | |
for item in $(find "${dir}") | |
do | |
# If the item is a regular file. | |
if [ -f "${item}" ] | |
then | |
# Check if the file is in use by someone else. | |
lsof -n "${item}" > /dev/null | |
# If no one is using the file. | |
if [ "$?" -ne 0 ] | |
then | |
# Get the file extension. | |
ext=$(echo "${item}" | awk -F "." '{ print $NF }') | |
# If the file is not a zip archive | |
# and does not exists a zip archive fo it | |
if [ "${ext}" != "zip" -a ! -f "${item}.zip" ] | |
then | |
# Create the zip archive but | |
# do not compress it (store it). | |
zip -0 "${item}.zip" "${item}" > /dev/null | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment