Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2256
  • Last Modified:

automated telnet script

I am working on a project that has a deadline and unfortunately don't have much of a test environment.  The app currently has the user telneting from his pc using boxed software to another box (type unknown) and running a script which will bring back a file.  I am trying to create a script that will run a telnet script (using telnet because I have no way of knowing if the other machine supports ssh or anything else).  The problem I have is that I don't have the 'expect' software on our unix box where I am doing my development and as it stands now, I will not be able to obtain this without an act of congress.  Is there any way that I can create a telnet script and pass it the login and password (along with the ip) and have it login to the other machine and run the script that is currently being run and return the file that is created by that script?  The reason I have to pass it a login & password and ip is that depending on the type of poll they are running for the telnet session, these values will be different (I have them set up in a database table so that it will know which login and password to use).  Any help would be greatly appreciated because I am at a loss.  Examples would be even more appreciated.

Cheryl
0
Cherylvan
Asked:
Cherylvan
  • 4
  • 3
  • 2
1 Solution
 
yuzhCommented:
telnet, FTP use plain text password, a sniffer can catch the user's password, you will
have a security problem with your application.

Consider use secure ftp (or scp) (secure ftp comes with secure shell, eg openssh),
or rsync + ssh. (you can setup ssh login without password, do a search at EE, you
can find a lot of them, I remember I answered it a few times).

telnet is NOT the tool for file transfer, if you still want a FTP script, here's a script

# !/bin/sh
/usr/bin/ftp -n  remote-hostname-or-ip <<EOF
user login-name password
lcd /home/dir-to-put-file
binary
put file1 file2
quit
EOF
exit

PS: there is NO WHITE space before EOF, if you what to downdown file, use "get" instead
      of put

      eg:
     put filename

man ftp
to learn more.
0
 
CherylvanAuthor Commented:
I don't have to really worry about a security issue since the machine I'm going to is behind a firewall (they don't even have password expiration).  Can you execute a script using ftp?

Cheryl
0
 
yuzhCommented:
It is a ftp script, all you need to do it to replace:

remote-hostname-or-ip  with a real machine name (or IP)

/home/dir-to-put-file   with a real /path-to/  where you want to put/get file

login-name  -- ftp loginname
password    --  ftp password


or modify the script to use loginname password as commandline args:


# !/bin/sh
# useage: scriptname login password
/usr/bin/ftp -n  remote-hostname-or-ip <<EOF
user $1 $2
lcd /home/dir-to-put-file
binary
put filename
quit
EOF
exit
#End of script

save the as myftp
then
chmod a+x myscript
man chmod
to learn more details.

to run the script, type in:
./myscript
or
/path-to/myscript



 

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CherylvanAuthor Commented:
Yuzh,

What I'm asking is if using this script, before the put filename statement, can I put a statement called 'test' for example which is really a script on the other machine which will run and create the filename which I will be bringing back to my machine.

Cheryl
0
 
CherylvanAuthor Commented:
Anyone,

I will give 100 points to anyone who will answer my question above.  

Cheryl
0
 
yuzhCommented:
Hi Cheryl,

    FTP is not a normal shell, you can't run script in ftp mode, but you can modify the script to run the remote scritp before doing FTP.
   you have 2 options to run remote command:

   1) Insecure way, use rsh:

rsh remotehostname "/path-to/yourscript"

you need to setup .rhosts file to make it work, see:
   http:Q_20654453.html#8763973

man rsh

  2) use secure shell
    ssh user@remote "/path-to/yourscript"

  If you want to use ssh in a script,  you can setup ssh without password:
http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/
http://www.experts-exchange.com/Networking/Linux_Networking/Q_20677059.html
http://bumblebee.lcs.mit.edu/ssh2/
http://www.cs.umd.edu/~arun/misc/ssh.html
http://pigtail.net/LRP/printsrv/keygen.html


   The newer version of remote command + ftp scrip would looks like:

# !/bin/sh
# run remote command first:
rsh remotehostname "/path-to/yourscript"
# you can replace rsh with the ssh version

# useage: scriptname login password
/usr/bin/ftp -n  remote-hostname-or-ip <<EOF
user $1 $2
lcd /home/dir-to-put-file
binary
put filename
quit
EOF
exit
#End of script

It is our Sunday (Australia time), other experts might give you a hand
if you need more help, otherwise I'll get back to you on Monday.

Have a nice weekend, cheers!



0
 
ahoffmannCommented:
if you use rsh you have rcp too, then you can get rid of ftp anyway
0
 
yuzhCommented:
ahoffmann,

    Good point! and if you can setup ssh get rid of FTP as well.
     
0
 
ahoffmannCommented:
ftp is obsolete in any case ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now