I need to build out the socat parameters in a file and have socat retrieve them. It there a header for this? I tried socat < parameterfile.txt, but that doesn't work.
Thanks
Your question is a bit vague on details, but let's suppose you want to run:
socat TCP-LISTEN:10000 -
You could create a file called params.txt which contains:
TCP-LISTEN:1000 -
and then run:
socat $(cat params.txt)
or if you prefer a more terse syntax:
socat $(< params.txt)
Related
What we have:
Multiple tor connections open at different ports.
What we want:
Create torify2, torify3, ... to handle multiple requests from different bash scripts simultanously.
Like:
bash_1.sh
torify curl ifconfig.me
...
bash_2.sh
torify2 curl ifconfig.me
...
bash_3.sh
torify3 curl ifconfig.me
...
I am new to stackoverflow. Feel free to comment so I can improve my skills in how to ask questions.
There are at least a couple of easy methods to do what you want since multiple Tor instances are already up and running.
Torify just calls torsocks so if you read the man page for torsocks, there aren't any options for specifying host/port for Tor, but it does use a config file which you can switch using the TORSOCKS_CONF_FILE environment variable.
The location of your config file may vary, but check /etc/tor/torsocks.conf for the default. Make a copy for each Tor instance, and change the TorPort in each file to a different Tor port.
Then, you can test that it works by running:
TORSOCKS_CONF_FILE=/tmp/torsocks-1.conf torsocks curl ifconfig.me
You can either run each instance like that, specifying a different config, or if you want to put that into a script, try:
torify1.sh
#!/bin/bash
TORSOCKS_CONF_FILE=/path/to/torsocks1.conf torsocks "$#"
Make one of the above scripts for each conf file and Tor SOCKS port you have running. The "$#" just passes all the command line arguments to your script to Torify.
You'd just run your script like: torify1.sh curl -v --compressed http://ifconfig.me/
Hope that helps.
I want to create shell script to invoke tftp transfer of particular file to my local machine
this is the operation i want to do
tftp 172.2.22.2
get file1_in_remote location file2_in_local_machine
quit
but I can't make it work, because when the 1st tftp command executes, control will got to tftp prompt. its just loook like this
tftp>
And it wont accept the 2nd and 3rd commands i have given in the shell script.
but when I exit from the tftp prompt, bash prints an error message like
get: command not found
quit: command not found
So How can I get it done
EDIT1:
tftp 173.32.52.12 -c get MyFile1.txt MyFile2.txt
tftp 173.32.52.12 -c get MyFile1.txt MyFile2.txt MyFile3.txt etc. etc.
these 2 commands not working with my ubuntu(14.0.4) system
You could use atftp
Install:
sudo apt-get install atftp
Use:
atftp 172.2.22.2 -g -r /remote/file.txt -l /tmp/local.txt
I found the solution.
file1_in_remote location = "/tftpboot/file1.txt"
file2_in_local_machine = "/home/file2.txt"
tftp 172.2.22.2 << !
#file names can be stored in varible
get ${file1_in_remote location} ${file2_in_local_machine}
quit
!
This worked for me
And There is one more solution
tftp 172.2.22.2 << 'EOF'
#explictely specify the file names. varibales wont accept here.
get /tftpboot/file1.txt /home/file2.txt
quit
EOF
but in second solution you have to give the file location explicit. And in the 1st solution file name can be stored in variable and we can use that variable in the "get" command.
The tftp is a tiny ftp variant and there is several implementations of this client protocol. The tftp-hpa package has a command option (-c) that make this possible as an one-liner in a script. Tested on Ubuntu 18.04:
apt install tftp-hpa
tftp 172.2.22.2 -c get /tftpboot/file1.txt /home/file2.txt
another single line option:
printf "bin\nget file.txt\n" | tftp 172.2.22.2
In the provisioning part of vagrant guide, there is a command wget -qO- 127.0.0.1 to check if apache is installed property.
Can anyone explain the command more in detail? I dont understand what the -qO- option does. Also, what is the meaning of wget to 127.0.0.1?
Thanks!
The dash after the O instructs output to go to standard output.
The q option means the command should be "quiet" and not write to standard output.
The two options together mean the instruction can be used nicely in a pipeline.
As far as added 127.0.0.1 as the source of the wget, that is there to make sure you have a local webserver running. Running wget on the commandline is faster than bringing up a browser.
I've been trying to use socat to respond on each connection to a socket it's listening to with a fake HTTP reply. I cannot get it working. It might be because I'm using the cygwin version of socat? I don't know.
Part of the problem is I want the second argument <some_file_response> not to be written to. In other words because it's bidirectional it will read what's in response.txt and then write to that same file, and I don't want that. Even if I do open:response.txt,rdonly it doesn't work repeatedly. system: doesn't seem to do anything. exec seems like it works, for example I can do exec:'cat response.txt' but that never gets sent to the client connecting to port 1234.
socat -vv tcp-listen:1234,reuseaddr,fork <some_file_response>
I want it to read a file to the client that's connected and then close the connection, and do that over and over again (that's why I used fork).
I am putting a bounty on this question. Please only give me solutions that work with the cygwin version from the windows command prompt.
Tested with cygwin:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat <some_file_response>"
If you do not want a complete HTTP response, leave out the echos:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"cat <some_file_response>"
Taken from socat examples
socat -vv TCP-LISTEN:8000,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat"
This one works:
socat -v -v -d -d TCP-LISTEN:8080,reuseaddr,fork exec:"cat http.response",pipes
Two things need to be aware,
should you add crlf, as in other answers. I recommend not.
crlf caused problem sending image
just use \r\n explicitly in http response headers.
without pipes, seems no data sent to client. browser complains:
127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
tested in cygwin.
== EDIT ==
If you want use inside cmd.exe, make sure PATH is correctly set, so that socat and cat can be found.
Say both socat.exe and cat.exe located under E:\cygwin64\bin
set PATH=%PATH%;E:\cygwin64\bin
Works in cmd.exe, with socat & cat from cygwin.
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.