Created
March 8, 2015 08:28
-
-
Save zeroxia/481da5f0e87abc058f41 to your computer and use it in GitHub Desktop.
xunlei-lixian batch invocation shell script
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/sh | |
LOG_FILE=./log.txt | |
if [ -z "$1" ]; then | |
echo "Usage: $0 LIST [LOG]" | |
exit 0 | |
fi | |
if [ -n "$2" ]; then | |
LOG_FILE="$2" | |
echo "Using log file: $LOG_FILE" | |
fi | |
truncate -s 0 $LOG_FILE | |
my_log() { | |
echo_opt="" | |
if [ "$1" = "-n" ]; then | |
echo_opt=-n | |
shift | |
fi | |
echo $echo_opt "$@" | tee -a $LOG_FILE | |
} | |
CNT=0 | |
CNT_FAIL=0 | |
cat "$1" | while read token name_state; do | |
name=${name_state% *} | |
state=${name_state##* } | |
CNT=$((CNT + 1)) | |
my_log -n "$CNT: $token | $state | $name: " | |
if [ "$state" != "completed" ]; then | |
my_log " omit incomplete item" | |
elif lx download -c "$token"; then | |
my_log "download success" | |
else | |
my_log "download failed" | |
my_log " $token $name_state" | |
CNT_FAIL=$((CNT_FAIL + 1)) | |
fi | |
done | |
if [ $CNT_FAIL = 0 ]; then | |
my_log "Total: $CNT" | |
else | |
my_log "Total : $CNT" | |
my_log "Failed: $CNT_FAIL" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment