-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-lookup.sh
executable file
·56 lines (41 loc) · 1.09 KB
/
user-lookup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Function to clean up and exit
cleanup() {
kill $SERVER_PID
exit 0
}
# Trap to ensure cleanup on script exit
trap cleanup EXIT
# Start the server in the background
npm start &
SERVER_PID=$!
# Wait for the server to be ready
while ! curl -s "http://localhost:3000" > /dev/null; do
sleep 1
done
# Get the username from the command line argument
USERNAME=$1
# Get the filename
FILENAME=$2
# Make sure a username was provided
if [ -z "$USERNAME" ]; then
echo "Usage: $0 <username> <outputfilename>"
cleanup
fi
if [ -z "$FILENAME" ]; then
echo "Usage: $0 <username> <outputfilename>"
cleanup
fi
echo 'It may take a while, wait.'
# Query the search endpoint and extract URLs
RESPONSE=$(curl -s "http://localhost:3000/search?username=$USERNAME")
# Extract URLs from the textarea in the response
URLS=$(echo "$RESPONSE" | awk '/<textarea id="resultsTextarea"/,/textarea>/{print}' | sed 's/<textarea[^>]*>//g; s/<\/textarea>//g')
# Print the URLs
if [ -n "$URLS" ]; then
echo ${URLS##*( )} | tr ' ' '\n' >> "./$FILENAME"
else
echo "No URLs found."
fi
# Clean up and exit
cleanup