I'm trying to script the telnet command to log into a server. My problem is that my username is my email so it has an # in it - so something like this fails:
telnet user#email.com#1.1.1.1
I've also tried this but it fails the same way.
set USER=user#email.com
telnet %USER%#1.1.1.1
Is there any way to escape the ampersand or is there another way to pass it to the telnet command? I've tried passing -l as follows but it does not work (as it still prompts me for a username so I'm guessing the telnet server doesn't support that and that would be out of my control to change).
telnet -l user#email.com 1.1.1.1
Ultimately, my goal is to get a doskey script with a command like the following
doskey t=telnet user#email.com#1.1.1.1
EDIT: Originally I mistakenly said ampersand but meant the at (#) symbol.
Related
I'm trying to connect to my server via SSH and issue some commands to it. For some reason it seems like the commands are getting cut "off".
Here is the code that does the putty connection as well as issuing the SSH commands:
./plink.exe ${USER}#${HOSTNAME} -pw ${PASS}<<SSH
cd /some/foo/bar
deploy_artifact.sh --instance development1 some_artifact.ear
APP_development1.sh restart
exit
SSH
For me it works, but on the machine of my colleague the issued SSH commands are getting cut off and thus are not interpreted correctly. For example deploy_artifact.sh is getting turned into ploy_artifact.sh (See the following the screenshot).
How can i prevent this? And what is causing this?
Thanks in advance for any help!
It appears the problem is with the plink and how it is used. The given example sends commands as a standard input, however I did not find in the plink manual any mention that it reads commands from the STDIN. It is better to avoid undocumented features, since they may not work correctly or the author may remove them without any notice. Instead, if you want to pass commands inline you should provide them as an argument, ie you either have to use a quoted text, or you can wrap heredoc in the "$(cat *heredoc* )" code, eg:
./plink.exe ${USER}#${HOSTNAME} -pw ${PASS} "$(cat <<SSH
cd /some/foo/bar
deploy_artifact.sh --instance development1 some_artifact.ear
APP_development1.sh restart
exit
SSH
)"
Or, you can keep the commands in a file and run the plink with the -m commands_file option.
I have a server that takes whatever data is sent to it and sends it back. With netcat on linux I am able to exectue the nc ip port command with an additional "argument" in a single line:
python -c print("Hello!") | nc ip port
This is equivalent to first running nc ip port to connect to the server, and later typing Hello! in the opened prompt to send the data.
While I know how to pass an output from a script to another script in windows (ex. here), I am fairly unsure how to achieve a similar result using telnet, as telnet ip port opens its own prompt (which means disabling windows commands).
I would like to know if it is at all possible with telnet to achieve what piping in linux does, or if there is a similar, minimalistic software that I could use on windows.
I need to pull something along the lines of "telnet root#192.168.2.99: irinject BACK"
however this refuses to work. There is no password required.
What is the correct syntax to perform this task using the terminal on Ubuntu 11.10?
If you absolutely must do it this way, use echo or etc. to pipe commands to the telnet session — and be ready to reinstall machines as they get hacked.
Strongly preferred is to use ssh with key access; you can even include the command that way.
ssh -i path/to/root-key root#host command
I have authenticated a server using authorized_keys push so I could run command ssh 192.168.1.101 from my system and could connect via server.
Now, I tried with library , It didn't worked for me
Net::SSH.start("192.168.1.209",username) do |ssh| #output=ssh.exec!("ls -l") end
as, This required username field. I want without username.
So , I tried this
system('ssh 192.168.1.209 "ls -l"')
It run the command for me. But I want the output in a variable like #output in first example. Is there any command any gem or any way by which I could get the solution ?
Any ssh connection requires a username. The default is either your system account name or whatever's specified in .ssh/config for that host you're connecting to.
Your current username should be set as ENV['USER'] if you need to access that.
If you're curious what username is being used for that connection, try finding out with ssh -v which is the verbose mode that explains what's going on.
you can pass parameters into %x[] as follows:
1. dom = ‘www.ruby-rails.in‘
2. #whois = %x[whois #\{dom\}]
Backquotes works very similar to "system" function but with important difference. Shell command enclosed between the backquotes is executed with standard output as result.
So, following statement should execute ssh 192.168.1.209 "ls -l" and puts directory files listing into #output variable:
#output = `ssh 192.168.1.209 "ls -l"`
I can connect to remote redis using the telnet command and get the value of "mytest" key. The following is working as expected.
[root#server shantanu]# telnet 10.10.10.100 6379
Trying 10.10.10.100...
Connected to 10.10.10.100 (10.10.10.100).
Escape character is '^]'.
get mytest
$14
this is first
But how do I use it in shell script?
I am used to connect to mysql using the following:
msyql -h10.10.10.100 -uroot -proot#123 -e"show databases"
Is a simialar syntax available for redis?
You can alternatively use redis-cli, included in redis
$ ./src/redis-cli --raw GET key
test
I don't know telnet, but with ssh you can:
ssh user#server "command arg1 arg2 ..."
for example
ssh user#server "ls -ltr | tail"
I would use a tool like wget, which is designed to get content from websites, and is very configurable and automaetable. You might even be able to get away with
export myTestKey=`echo "get mytest" | telnet 10.10.10.100 6379`
If the conversation needs to be more complex than that, I would use telnet in combination with expect, which is designed for trigger and response conversations.