Timing out a SSH

I need to make it so an autmated process which involves ssh, times out if ssh prompts for a password. Most of the time it shouldnt prompt for a password. But if it does i need it to time it out or get a status and stop the ssh and log that the ssh failed and move onto the next server. Is there any way of doing this? Im using Bash

There is a parameter in the sshd_config file that you can set.

LoginGraceTime 60 # the connection will timeout in a minute if no reply from client
testSSH()
{
	ssh -1 infra@dev1cas ls &
}
PARENT=$$
echo $PARENT
testSSH
sleep 4s
SSHID=`ps | grep $PARENT|grep ssh|awk {'print $2'}`
echo $SSHID
kill -9 $SSHID
testSSH
sleep 2s
SSHID=`ps | grep $PARENT|grep ssh|awk {'print $2'}`
kill -9 $SSHID

This is an example of what im trying to do. Im running a script and it goes out and backs up files. And ssh shouldnt ask for a password but if for any odd reason it does i need to not do it. The code above is what ive been working on but it prompts for a password no matter what even when i put it in the background. I dont know of anyway to get it to stop asking for a password

Have you setup key-based authentication between the localhost (where the script is to run) and the remotehosts (where the ssh connection is to be made)? If not, you will be asked for a password. You can search on google for how to setup key-based authentication.

Yes it is setup but if that fails for any reason i need the script to move on

If you are using key-based authentication, have you tried configuring your ssh_config to attempt PubkeyAuthentication only? If pubkey fails, it should disconnect you immediately.

can i edit taht at the start of a script then change it back when the script is finished

Check the man pages for SSH. You can (should be able to) define a specific config file when invoking the SSH command, so you actually don't have to edit anything, just have a separate config file that you can invoke when you issue the SSH command, something like:

 ssh -F myConfigFile  remoteHost

Check your man pages for the right syntax of your SSH version.

Okay i got it i set NumberOfPasswordPrompts to 0 and then it doesnt ask thanks

testSSH()
{
	ssh -1 infra@dev1cas ls &
}
PARENT=$$
echo $PARENT
eval `testSSH` &
sleep 4s
SSHID=`ps | grep $PARENT|grep ssh|awk {'print $2'}`
echo $SSHID
kill -9 $SSHID
testSSH
sleep 2s
SSHID=`ps | grep $PARENT|grep ssh|awk {'print $2'}`
kill -9 $SSHID
wait

You mean something like this?