0

I want to run the following commands in bash script form in Solaris 10:

$ telnet localhost 25
debug
quit

How do I handle this?

  • Do you have expect installed, either as a binary or as a Perl module? – Jeff Schaller Jul 15 '15 at 15:56
  • I want write this with builtin packages and modules. – Gohar Jul 20 '15 at 2:55
1

If you have any luck with having bash configured with --enable-net-redirections, Bash's special redirections might be useful:

cat <<EOF >/dev/tcp/localhost/25
debug
quit
EOF

When you're also interested in the output from the server:

exec 3<>/dev/tcp/localhost/25 # open localhost:25 as fd 3
cat <<EOF >&3 # write to fd 3
debug
quit
EOF
cat <&3   # read from fd 3
exec >&3- # close fd 3
  • # cat u > /dev/tcp/localhost/25 /dev/tcp/localhost/25: cannot create – Archemar Jul 15 '15 at 12:01
  • @Archemar It seems not all the distro/system come with the bash with this feature enabled. I updated my post. – yaegashi Jul 15 '15 at 12:25
0

Edit: as per sugested, and after testing, this work on linux, but not on solaris as OP request.

pipe style

(echo debug ; echo qui ) | nc localhost 25

or (heredoc style)

nc localhost 25 <<EOF
debug
quit
EOF

on my ubuntu, telnet do not take input, while netcat does.

  • 1
    It may be better to use netcat (sometimes also available as nc as that waits for the remote connection to close before quitting; piping into telnet may cause telnet to stop before the remote has had a chance to react. – wurtel Jul 15 '15 at 9:28
  • nc command not found. This is same for netcat. – Gohar Jul 15 '15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.