Created
September 6, 2014 04:58
-
-
Save kai5263499/c3b4549d396445ca63ad to your computer and use it in GitHub Desktop.
This script reads the first entry from a text file and downloads it. Includes locking to ensure only one download is run at a time. After the download is complete, the first entry in the text file is removed, effectively creating a queue in bash of sorts.
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 | |
cd ~ | |
LOCKFILE="download-running" | |
if [ -f $LOCKFILE ];then | |
exit 0 | |
fi | |
touch $LOCKFILE | |
DOWNLOAD_FILE="download-list.txt" | |
FILE=$(head -n1 $DOWNLOAD_FILE) | |
echo "Copying $FILE" | |
cd downloads | |
scp -C "$FILE" remoteserver:/destination/ | |
cd ~ | |
cat $DOWNLOAD_FILE | sed -e '1,1d' > ${DOWNLOAD_FILE}-new | |
mv ${DOWNLOAD_FILE}{-new,} | |
rm $LOCKFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment