Invoking Application in Shell Script

Hi All,

I have a scenario :

  1. A list of servers naming server21, server 22, server 23 etc. This list of servers is separate for my environments.

Env1 has 3 server
Env2 has 5 serves
Env3 has 10 servers

  1. Each server accesses application through which I want to invoke some method. So the URL for Env1 and Server21 in it would be : http://Server21/abc.click.clear etc.

Now I want to make a shell script which invokes all these methods by Env wise and then server wise. I know wget will do the invoking but I am unable to make out the structure of the script. Can someone help me put on this?

If I understand correctly, you want to run a wget on a specific url on each server, and each server is in one of three environments?

If the app is always the same then it's just a matter of a 'for' loop:

for environment in `cat ListofEnvironments.txt`
do
  echo "Environment: ${environment}"
  for server in `cat ListOfServersIn${environment}.txt`
  do
    echo "  Server: ${server}"
    wget -q -O "${server}_abc.click.clear-output.txt" "http://${server}/abc.click.clear"
  done
done

Not tested, you might need some slight debug.

If you want to run in parrallel instead (faster but everything runs at once), just add a n ampersand ('&') to the end of the wget line.

The servers have different names for each environments and the environment names are also different.

Give us an example and we should be able to help more.

Environment 1 name : DEV

Server name : aedcmap021, aedcmap022

Environment 2 name: Test

Server name : aetcmap002, aetcmap030

Env 3 name : QA

aeqcmap021, aeqcmap023

If you make a file for each enviroment, naming it as such,
containing each its servers (without the leading 'http://') it'll be like:

# untested
cd /path/to/list/files
for ENV in $(ls);do
    echo "Working with $ENV"
    while read SERVER;do
        echo " * $SERVER"
        wget -q -O "${SERVER}_abc.click.clear-output.txt" "http://${SERVER}/abc.click.clear"
    done < $ENV
done

Hope this helps

Thanks SEA for the code.

I did the same way but called my files outside the for loop. Yeah the basic approach remains same. Have a look if you want to.

I love Scripting.

Thanks all PROBLEM Solved

Thanks, but its not much diffrent from Smiling Dragon.

Now with all the 'data', i'd make it like:

#!/bin/sh

TASKS=""
cd /path/to/files

usage() 
{ 
cat << EOF 
usage: $(basename $0) \[all|dev|test|qa|dr|pp|prod\] 
 
Check Startup Status 
 
OPTIONS: 
   -h      Show this message 
EOF 
}


for ENV in $@;do
    if [[ -f $ENV ]]
    then    echo "Adding $ENV to worklist"
            TASKS+=" $ENV"
    elif [[ all = "$ARG ]]
    then    echo "Do all"
            TASKS="$(ls)"
    else    echo "Error?"
            usage    # Call the 'help function'
            exit 1
        fi
done

for ENV in $TASKS;do
    echo "Working with $ENV"
    while read SERVER;do
        echo " * $SERVER"
        for folderName in HomePageCache PLPContentCache NoResultPageCache;do
            SUBPATH="/dyn/admin/nucleus/com/newlook/droplet/$folderName/?invokeMethod=flushCache&submit=Invoke+Method"
            url="http://${SERVER}${SUBPATH}"
            rm -r $folderName # Removing data befor downloading
            wget -P $folderName --timeout=5 --tries=3 --http-user=admin --http-password=admin "$url"
        done
    done < $ENV
done