Add linkloc.sh

master
89wc 2023-09-04 19:56:20 +00:00
parent 12d6bea0e3
commit a57e6fe41f
1 changed files with 16 additions and 0 deletions

16
linkloc.sh 100644
View File

@ -0,0 +1,16 @@
#!/bin/bash
if [ -z $1 ]; then echo "linkInvalid"; exit 1; fi;
URL="${1}"
HEADS=$(curl -L --head --silent -A "getloc" "$URL");
STATUS=$(echo "$HEADS" | head -1);
LOCATION=$(echo "$HEADS" | grep -ie '^location' | grep -e 'http../' \
| tail -1 | cut -d'?' -f1 | cut -d' ' -f2 | sed 's@^.*reddit.com@https://old.reddit.com@' \
)
if [ -z "$LOCATION" ]; then
echo "$URL"; exit 2;
fi
echo "$LOCATION"