Can anyone help me how to exit a shell script if a unix command inside does not return any value for 10 seconds?
The scenarios is like this.
I want to login to a application using shell script where the connection string is mentioned.but suppose this connection string is not responding means after passing the password it is getting hanged, not getting into that application.In this case i want the connection string to wait for sometime say 10 seconds and after that exit the shell program.
If command/program has done correctly for *nix systems, it return 0 if okay and not 0 if there is some error. Usually command doc include comments for every exit codes.
Variable ? include last command exit status.
some_command
stat=$?
(( stat != 0 )) && echo "Some problem $stat" && exit 1
So test mysql command with correct values and not so correct values.
After command check exit status
Hunting for timeout in man mysql I find it mentioned right below --var name=value:
You can also set the following variables by using --var_name=value. The
--set-variable format is deprecated.
o connect_timeout
The number of seconds before connection timeout. (Default value is
0.)
Ergo mysql --connect_timeout=10 ... sounds like what you want.