# Retrying a remote connection after failure

**URL:** <https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267>\
**Category:** Shell Programming and Scripting\
**Created:** [October 14, 2010, 12:52am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267 "2010-10-14T00:52:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![interceptor16](https://community.unix.com/letter_avatar/interceptor16/32/5_5575768a8748004e209b776fc1b2916d.png) [@interceptor16](https://community.unix.com/u/interceptor16)\
**Post date:** [October 14, 2010, 12:52am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/1 "2010-10-14T00:52:46Z")

</div>

Hi all,

I am new to this forum and want an urgent help from you experts. I am currently using SunOs 5.10.

I have a .cfi file which contains some commands to be executed in a node(MSC node in telecom) To connect to a node (for eg node name is MSC1) we have a shell script that has the following command

```nohighlight
/bin/cfi -F /home/scriptdt/scr/script/file.cfi -N MSC1 > outputfile

```

(cfi utility is invoked from /bin, -F option followed by the path of file.cfi which contains the commands, -N connects to the network element MSC1 and the o/p is stored in outputfile)

there are many lines like this for connecting into different nodes in the script file.

Now the trouble is sometimes due to network issues the connection to the nodes(MSC1 in this case) is not obtained and the execution moves into the next line in the script.So that particular node is missed and results in missing data. I want to retry to the node after some time when all the lines have been performed.

there is an option -b in cfi help list (tries after a delay) but the problem is if i use -b option it gets stuck onto that particular line/Node only and does not proceed to other commands until the connection is obtained and the work is done.

Please help me out how to come out of this situation urgently. I am a newbie to shell scripting.

---------- Post updated at 10:22 AM ---------- Previous update was at 10:03 AM ----------

any help?

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [October 14, 2010, 1:27am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/2 "2010-10-14T01:27:50Z")

</div>

Bumping up threads is not allowed by the forum rules. Also check this:

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the [Emergency UNIX and Linux Support Forum](http://www.unix.com/emergency-unix-linux-support-help-me/). This forum is given a higher priority than our regular forums.

Posting a new question in the [Emergency UNIX and Linux Support Forum](http://www.unix.com/emergency-unix-linux-support-help-me/) requires forum [Bits](http://www.unix.com/credits.php?do=banking). We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums

---

<div class="post-metadata">

**Author:** ![interceptor16](https://community.unix.com/letter_avatar/interceptor16/32/5_5575768a8748004e209b776fc1b2916d.png) [@interceptor16](https://community.unix.com/u/interceptor16)\
**Post date:** [October 14, 2010, 1:56am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/3 "2010-10-14T01:56:19Z")

</div>

Hi Mods,

Thanks for diverting me to the correct thread. However I haven't used urgent or emergency words in the title of the thread.

Being new it will take me few days to get used to this highly valuable forum.

Thanks.  
Regards :o

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [October 14, 2010, 2:23am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/4 "2010-10-14T02:23:46Z")

</div>

You did not use in the subject but in your post:

> [@](#):
>
> I am new to this forum and want an urgent help from you experts

and as the reminder says

> [@](#):
>
> remove words like "Urgent" etc. (from your subject and post)

Also bumping the thread up after some minutes (if I got the time right), just because no answer was there already, fits to the "urgent" 😉

Anyway I think you got the message. No problem - keep the [Forum Rules](http://www.unix.com/misc.php?do=cfrules) in mind and happy posting 🙂

---

<div class="post-metadata">

**Author:** ![felipe.vinturin](https://community.unix.com/user_avatar/community.unix.com/felipe.vinturin/32/1840_2.png) [@felipe.vinturin](https://community.unix.com/u/felipe.vinturin)\
**Post date:** [October 14, 2010, 9:06am UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/5 "2010-10-14T09:06:48Z")

</div>

I tried to find some documentation about CFI and the cfi binary, but no success. It maybe apply unix return codes where:

- Return Code = 0 -\> Success
- Return Code != 0 -\> Fail

So you can try this:

```nohighlight
execCFI ()
{
	cfiScript="${1}"
	cfiRunNode="${2}"
	
	# Default number of retries is 5
	numRetries="${3:-5}"
	
	if [! -f "${cfiScript}"]
	then
		echo "ERROR: CFI script is not a valid file: [${cfiScript}]."
		return 1
	fi

	currDateTime=`date +"%Y%m%d-%H%M%S"`
	cfiOutFile=`basename "${cfiScript}"`
	cfiOutputFile="${cfiOutFile}_${currDateTime}"
	
	cfiReturnCode=1
	
	while [${cfiReturnCode} -ne 0 -o ${numRetries} -ge 0]
	do
		/bin/cfi -F "${cfiScript}" -N "${cfiRunNode}" 1>"${cfiOutputFile}" 2>&1
		cfiReturnCode=${?}
		numRetries=`expr ${numRetries} - 1`
	done
        return ${cfiReturnCode}
}

execCFI "/home/scriptdt/scr/script/file.cfi" "MSC1" "5"
execCFIRetCode=${?}

if [${execCFIRetCode} -ne 0]
then
         echo "ERROR: Failed to execute node: [MSC1]."
fi

```

I hope it helps.

Regards.

---

<div class="post-metadata">

**Author:** ![interceptor16](https://community.unix.com/letter_avatar/interceptor16/32/5_5575768a8748004e209b776fc1b2916d.png) [@interceptor16](https://community.unix.com/u/interceptor16)\
**Post date:** [October 14, 2010, 1:33pm UTC](https://community.unix.com/t/retrying-a-remote-connection-after-failure/275267/6 "2010-10-14T13:33:14Z")

</div>

Hi,

Thanks for the reply. I got the work around.

CFI is a utility developed by my employer company and used internally , that is why it can't be found over the net.

Thanks anyways 🙂
