LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2012, 04:44 AM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Rep: Reputation: 135Reputation: 135
script to telnet unix to unix and do some task


I have an IRIX box with default shell ksh and another AIX box with csh.

I have to telnet from IRIX to AIX and in AIX I have to run some executables say:echo/cat on contents of file using script with loop.

This is what I did.

Code:
( echo username; sleep 1; echo password; sleep 1; echo cd /path/to/file ;echo pwd;echo cat file; echo pwd ; echo exit ) | telnet 10.10.10.10
I successfully able to run the command cat on the file.

But I want like this, which not working.

Code:
( echo username; sleep 1; echo password; sleep 1; echo cd /path/to/file ;echo pwd;echo foreach i (`cat file`); echo echo $i ; echo end; echo exit ) | telnet 10.10.10.10
Giving error :

syntax error at line 4 : `(' unexpected - with
Code:
(`cat file`)
foreach: Too few arguments and Cannot open file: No such file or directory : with
Code:
`cat file`

Last edited by divyashree; 07-14-2012 at 04:46 AM.
 
Old 07-14-2012, 05:04 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,101

Rep: Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497
Add quotes:
Code:
(echo username;
       sleep 1;
       echo password;
       sleep 1;
       echo 'cd /path/to/file';
       echo 'pwd';
       echo 'foreach i (`cat file`)'; 
       echo 'echo $i';
       echo 'end';
       echo 'exit') | telnet 10.10.10.10
 
1 members found this post helpful.
Old 07-14-2012, 07:46 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
Thanks Nevem..
 
Old 07-26-2012, 02:41 AM   #4
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
Dear Naveem, instead of doing echo $i, while I am running any executables on $i, it runs only on the 1st value of $i and not looping over to the next values and is ended with the message:

Quote:
Connection closed by foreign host.

Last edited by divyashree; 07-26-2012 at 05:54 AM.
 
Old 07-26-2012, 05:02 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,101

Rep: Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497
Please create a minimal example that presents the problem, and paste it in.
 
Old 07-26-2012, 06:09 AM   #6
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
Thanks for the respose:

My scenario:

My script looks like this:

Quote:
(echo username;
sleep 1;
echo password;
sleep 1;
echo 'cd /path/to/file';
echo 'pwd';
echo 'foreach i (`cat file`)';
echo 'metasapi.x $i';
echo 'end';
echo 'exit') | telnet 10.10.10.56
where metasapi.x is the executable which runs on the values read from the file to perform certain tasks .

File contains some data queried from db in each hour.

suppose file contains:

4090121246
4090121241
4090121243

After telneting, metasapi.x only executes on the first one
Quote:
metasapi.x 4090121246
and give the response successful and then the message
Quote:
Connection closed by foreign host.
Instead of that it should be like this:
Quote:
metasapi.x 4090121246
successful
metasapi.x 4090121241
successful
metasapi.x 4090121243
successful
then telnet should be closed

But if using echo instead of the executable, it echos all in loop one after another.

Last edited by divyashree; 07-26-2012 at 06:37 AM.
 
Old 07-26-2012, 06:45 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
why don't you use rsh or ssh ?
 
1 members found this post helpful.
Old 07-26-2012, 07:10 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,101

Rep: Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497
I tried, but couldn't use telnet this way... perhaps expect could help?
 
Old 07-26-2012, 07:23 AM   #9
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by bigearsbilly View Post
why don't you use rsh or ssh ?
ssh is not available in that AIX machine, I will try for the auto login by rsh and will post the result.
 
Old 07-26-2012, 07:25 AM   #10
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by NevemTeve View Post
I tried, but couldn't use telnet this way... perhaps expect could help?


I tried with expect, but I was able to auto login and able to run the executable, but unable to run the loop in that.
 
Old 07-27-2012, 03:28 AM   #11
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,373

Original Poster
Rep: Reputation: 135Reputation: 135
I think its solved now. I used while loop in main script and rsh in expect script as below

This in my main script and called:

Code:
function expectrsh {
if [ -e Track_File3 ]
then
 while read dml
 do
  ./expect1.sh $dml
 done < Track_File3
fi
}
And my expect1.sh looks like below to use rsh:

Code:
#!/usr/bin/expect  

set ip "10.10.10.56" 
set user "user"
set password "pass" 
set dml [lindex $argv 0]
spawn rsh "$user\@$ip"
expect "Password:"
send "$password\r";
expect "%"
send "cd /path/to/exe\r"
expect "%"
send "metasapi.x $dml\r"
expect "%"
send "pwd\r"
expect "%"
send "logout\r"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Telnet script on Unix machine without expect cristoph_ Programming 7 12-24-2008 11:23 AM
LXer: The DB2 SQL-based Admin Task Scheduler for Linux and UNIX LXer Syndicated Linux News 0 09-23-2008 05:10 PM
telnet windows m/c from unix shell script ann124 Programming 1 11-10-2004 02:26 PM
What is the most important task that should be performed on the Unix server? thatgentleman Linux - General 7 03-23-2002 10:02 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 07:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration