arxoft
arxoft

Reputation: 1475

What's happening in this SH file?

I think it's a bash coding. It's about testing load server via curl. But I don't get it at all. Can anyone please explain what's going on in this file?

curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://admin.yumyummi.com/api/dbsync/getUpdateLogs?app_last_update_time=&curl=a{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!"  

for job in $pidlist do 
  echo $job     
  wait $job || let "FAIL+=1" 
done  

if [ "$FAIL" == "0" ]; then 
  echo "YAY!" 
else 
  echo "FAIL! ($FAIL)" 
fi

Upvotes: 1

Views: 274

Answers (1)

Saucier
Saucier

Reputation: 4360

Please see the comments inside the script:

# Curl the url http://myurl.com/ - but don't output anything (-s)
# Try different parameters of the url: http://myurl.com/?1-1 (not quite sure about the brackets)
# Send the process to the background (&)
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &

# Add the process id (pid) of the most recent process ($!) to a variable named pidlist
# In that case it's the pid of the previous curl command
pidlist="$pidlist $!"

curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://myurl.com/?{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!" 
curl -s "http://admin.yumyummi.com/api/dbsync/getUpdateLogs?app_last_update_time=&curl=a{1,2,3,4,5}-[1-1000]" &
pidlist="$pidlist $!"  

# For each pid in the pidlist variable do something
for job in $pidlist do

  # Echo/output the process id
  echo $job

  # Wait for the process to finish. If the process returns an error add 1 to the variable FAIL
  wait $job || let "FAIL+=1" 
done  

# If the variable $FAIL is 0
if [ "$FAIL" == "0" ]; then

  # Echo/output the string "YAY!"
  echo "YAY!"

# If the variable $FAIL is not 0
else 

  # Echo/output the string "FAIL!" + the integer value of the variable $FAIL representing the
  # number or errors
  echo "FAIL! ($FAIL)" 
fi

Upvotes: 1

Related Questions