Skip to content

Instantly share code, notes, and snippets.

@kai5263499
Created September 6, 2014 04:58
Show Gist options
  • Save kai5263499/c3b4549d396445ca63ad to your computer and use it in GitHub Desktop.
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.
#!/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