stagger ssh command to multiple machines

Good day,

I am extracting information from Apache log files from 41 servers. Every day I have 7 cronjobs scheduled to do this for me and it works beautifully :D... only problem is that it takes about 6-9 hours to run through, as the script runs about 6 ssh commands for each box then goes to the next one.

I am sitting in the development environment and can only ssh in as readonly on the servers, which all sit in prodcution environment. I am not allowed to do anything on the production environment, so ssh is my only option for this one.

Here is a breakdown of my script structure
#!/usr/bin/ksh

ssh_function1()
}
Error_HTTP_403_cre()
{
if `test -f $sshExportFile`; then rm $sshExportFile ; else touch $sshExportFile ; fi
ErrorDesc="HTTP/1.1 403"
ssh readonly@$ServerIP 'YEAR=xx;DAY=xx;MONTH=xx;LMONTH=xx;for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \
16 17 18 19 20 21 22 23; grep -c "HTTP/1.1\" \"403" "/var/SP/log/apache/cre/access.log_$YEAR$MONTH$DAY_"*$i.gz ;done'>>$sshExportFile (Export file on dev box)
Sum_to_Oracle #Oracle insert function
echo "$ErrorDesc: $Value" >> $EFCREE
rm $sshExportFile
}

sshfunction()
{
ssh_function1 ; ssh_function2 ; ssh_function3 ; ssh_function#....
}

Servername="A"; serverip=1.1.1.1 ; sshfunction
Servername="B"; serverip=1.1.1.2 ; sshfunction
Servername="B"; serverip=1.1.1.3 ; sshfunction
#... and some more servers

The same commands run on all the servers.

Is there a way I can run the commands that after 5 minutes the script starts with the next server, while still running the sshfunction for the previous servers..:confused:

so... time=0
Servername="A"; serverip=1.1.1.1 ; sshfunction #kicks off and runs till finished
time=0+5
Servername="B"; serverip=1.1.1.2 ; sshfunction #kicks off and runs till finished
.. and so on and so forth.

Thanks in advance
msullivan

Try this:

Servername="A"; serverip=1.1.1.1 ; sshfunction &
sleep 300
Servername="B"; serverip=1.1.1.2 ; sshfunction &
sleep 300
Servername="B"; serverip=1.1.1.3 ; sshfunction &

But if I make it a solid background process...
Servername="A"; serverip=1.1.1.1 ; sshfunction &

Will that put all the functions in sshfunction() at the same time in the background?
As I have around 5 functions in the sshfunction and each of them on a
for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 loop.

I am assuming that putting the command sshfunction in the background (&), it will still execute all internal functions in the normal sequence..?
And not all 5 functions x 24 at the same time on that server..

Thanks Perderabo
I tested the scripts and they work like a charm.. Now I just have to deal with output redirect... I'm sure >>$logFile 2>&1 & will do the trick.

Thanks again, for making my life a little easier.