Make a shell script execute commands in telnet or programs
I would like to make a shell script that executes commands on a device that I telnet to or in programs such as FTP or OpenSSL. I have already found a method in FTP, which would look something like this:
#!/bin/sh HOST='0.0.0.0' USER='User' PASSWD='Pass' FILE='~/Desktop/file.txt' RFILE='file.txt' ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary passive put $FILE $RFILE quit END_SCRIPT exit 0
How can I do something similar with devices I telnet to or in different programs?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
some time ago I needed something similar. You can try with something like this:
#!/bin/sh HOST='0.0.0.0' USER='User' PASSWD='Pass' CMD='' ( echo open "$HOST" sleep 2 echo "$USER" sleep 2 echo "$PASSWD" sleep 2 echo "$CMD" sleep 2 echo "exit" ) | telnet
PS1: I user “sleep 2” because I am accessing through satellite. If it’s LAN, maybe you don’t need “sleep” at all.
PS2: just enter what you need in the CMD variable
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0