forked from xyzale/my-stuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-diff.sh
58 lines (40 loc) · 1.26 KB
/
api-diff.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
57
#!/usr/bin/env sh
##################################################
# Takes a text file as input containing a list
# of endpoints to call. Example:
# ./diff.sh endpoints.txt
# Compares the result and returns the difference
# between the result from production server
# and the local vagrant machine
##################################################
# reading the file
file="var/log/$1"
vagrant="http://website.com.vagrant"
production="http://website.com"
while IFS= read -r line
do
echo "------------\nURL: $line \n------------\n"
# ----------------------
# call to vagrant machine
CT="Content-Type:application/json"
RESPONSE="curl $vagrant$line -H $CT"
$RESPONSE > /tmp/vagrant.txt
echo "-- Vagrant response saved \n"
# ----------------------
# call to production server
CT="Content-Type:application/json"
RESPONSE="curl $production$line -H $CT"
$RESPONSE > /tmp/production.txt
echo "-- Production response saved \n"
# ----------------------
# difference between responses
diff=$(diff /tmp/vagrant.txt /tmp/production.txt)
echo "DIFF: \n $diff \n\n"
if [ ! -z "$diff" ]; then
echo '-------------------- DIFF!!!! \n\n'
echo $line
echo $line >> /tmp/diff.txt
fi
rm /tmp/vagrant.txt
rm /tmp/production.txt
done < "$file"