Skip to content

Instantly share code, notes, and snippets.

@dkosmari
Last active July 3, 2024 21:38
Show Gist options
  • Save dkosmari/22f91053921c305111083e914feb4fbf to your computer and use it in GitHub Desktop.
Save dkosmari/22f91053921c305111083e914feb4fbf to your computer and use it in GitHub Desktop.
A shell script to fetch Wii U crash logs through FTPiiU plugin. Requires wget and sed.
#!/bin/sh -e
# This script copies crash logs from a Wii U running Aroma with FTPiiU plugin.
# It depends on lftp command.
WIIU_ADDRESS=${1:-wiiu}
TEMP_PATH=$(mktemp -d)
if [[ -z "${TEMP_PATH}" ]]
then
echo "failed to create temporary directory"
exit 1
fi
function cleanup {
rm -rf "${TEMP_PATH}"
echo "Deleted temp directory ${TEMP_PATH}"
}
trap cleanup EXIT
REMOTE_SYS="storage_slc/sys"
# obtain the console serial id
(cd "${TEMP_PATH}" && \
lftp -c get "ftp://${WIIU_ADDRESS}/${REMOTE_SYS}/config/sys_prod.xml")
SYS_PROD_PATH="${TEMP_PATH}/sys_prod.xml"
SERIAL_ID=$(sed -rn \
's|[[:space:]]*<serial_id[^>]*>([[:digit:]]+)</serial_id>|\1|p' \
"${SYS_PROD_PATH}")
(cd "${TEMP_PATH}" && \
lftp -c mirror "ftp://${WIIU_ADDRESS}/${REMOTE_SYS}/logs")
# dump logs into FW<serial>/<datetime>
FW_PATH="FW${SERIAL_ID}"
DATETIME_PATH=$(date "+%F %H-%M-%S")
DEST_PATH="${FW_PATH}/${DATETIME_PATH}"
mkdir -p "${DEST_PATH}"
echo "Copying logs to ${DEST_PATH}"
# rename all log files to match their timestamps (first line in the log)
for f in "${TEMP_PATH}"/logs/*.log
do
FILE_TIME=$(head -n 1 < "$f")
FILE_NAME="${FILE_TIME//:/-}"
cp "$f" "${DEST_PATH}/${FILE_NAME}.log"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment