The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to manipulate a message count for the same IP @ diff session gobinath Shell Programming and Scripting 1 05-28-2008 04:13 PM
running script after closing telnet shinjeck SUN Solaris 2 10-29-2007 07:52 AM
Telnet Session to AIX bluebee UNIX for Dummies Questions & Answers 1 08-07-2007 04:19 PM
Error closing read file ALTRUNVRSOFLN High Level Programming 1 09-18-2006 12:29 PM
Telnet Session pathanjalireddy Shell Programming and Scripting 6 04-06-2005 11:41 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-23-2009
farahzaiba farahzaiba is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 6
closing a telnet session on error, in a shell script

I am using a shell script to telnet into a remote unix server and execute certain commands. But if any command being executed remotely, throws an error, the script just hangs. And the telnet session does not get closed.

I want to be able to close the session and complete the script execution in case of an error or otherwise.

Below is the script. Any help will be appreciated.
#!/bin/sh
( echo open host
sleep 1
echo user
sleep 5
echo pswd
sleep 4
sourceDir=$1 ; filename=$3 ; destDir=$2
echo "cd ${sourceDir}"
sleep 1
echo "cp -rf ${filename} ${destDir} && \
cd ${destDir} && \
$cmd ; exit"
) | telnet


I also want to be sure the previous command got executed before proceeding to execute the next command, which is why I'm using '&&'. This, not by using "sleep", but some other way of ensuring the earlier command did get executed successfully.

The above script cribs at the echo of the last command. Snippet of the error is

uctvd201:/opt/epds/EPDSDV01/epdata/SPONSOR/0000_071/test [EPDSDV01]# d && \ <
sh: : Execute permission denied.
uctvd201:/opt/epds/EPDSDV01/epdata/SPONSOR/0000_071/test [EPDSDV01]# ad && \ <
sh: : not found.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0