For the sake of context, I am developing a system which would allow "remote" access to an NVidia Xavier. Unfortunately in its current housing, the display port is entirely blocked unless the entire unit is taken apart. A USB port is available, which is being used to connect to a wireless keyboard & mouse. I have already written a Gstreamer pipeline that I can execute via SSH which will capture the display and stream it to another local machine.
The problem I am running in to is, as the unit is portable, the network it is connected to and subsequent IP will be constantly changing, but I need to know it to be able to SSH into the unit.
I am trying to write a (what I thought to be simple) bash script that will send a timestamp and the IP of the unit to a Slack channel on boot via a webhook that is effectively the following command (IP and slack URL generalized):
curl -X POST -H 'Content-type: application/json' --data '{"text":"Tue Jul 14 15:26:50 EDT 2020 IP: XX.X.X.XX"}' https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
The JSON payload will be changing each time the script is run, dependent on the results of hostname -I and date.
I have tried creating an array with the desired data in it using:
command=( -X POST -H 'Content-type: application/json' --data \'{\"text\":\")
command+=("$(date)")
command+=("$(hostname -I)")
command+=(\"}\' https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX)
curl command
but receive an error curl: (6) Could not resolve host: command.
I have very little experience writing bash scripts and am likely missing something incredibly obvious to everyone else. However, using echo "${command[*]}" does show an output that matches the working command. Any advice would be greatly appreciated.
This is a common error when using variables in bash - when you set them, you don't prefix them with a $, but when you reference them, they must be prefixed with a $ in order to be expanded. So in your case, you likely want to use: curl $command instead of curl command
Related
I want to monitor events from my docker daemon in a C application, but I'm unclear how to subscribe to that API. This is probably just a Rest API in C question. All of the examples I find with Docker do a single call and response.
I feel like there should be a better way to do this, but it's possible to just read off chunks of events from the stream:
echo -e "GET /v1.20/events?since=1500032589&until=1500035000 HTTP/1.1\r\nHost:\r\n" | nc -U /var/run/docker.sock
You just need to track the time, and realize that until is non-inclusive.
I'm trying to use AT commands to setup a BGS2-W modem on a custom board to connect to a site over TLS, but the modem is not reacting to my commands and no certificates are being set.
I'm using the command
AT^SBNW
to send the commands as documented in Transport Layer Security for Client
TCP/IP Services doc (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf#page=8).
Unfortunately, the document provides no examples, and I haven't been able to find any samples showing the usage of this command online.
The document linked has a java commandline tool attached that will send a cert from a PC, however I am unable to use this tool (I don't have the connection to the modem).
If anyone has any idea's on how to use this command I could very much use the help.
Note: I'm trying to set the certificates from within code running on a PIC18 - this isn't a final incarnation, I just need the certificates loaded so I can connect to our secure server.
Well, guess this one isn't going to find an answer anytime soon :)
So, its fairly easy to capture the output from the javatool - I'm using Com0Com to emulate 2 connected ports, then using termite to manually input on one port while telling the java app to connect to the other.
The first query from the java app expects an "OK" response, I find it easiest to send the response before starting the java app (I guess it gets cached in the recv buffer of the emulated port).
The javatool then sends "AT^SBNW=is_cert,1\r", and you can type in the reply in termite "SECURE CMD READY: SEND COMMAND ..."
After this a large binary dump comes through. You can decode the dump using the structure described in Application Note 62 (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf). That should get all the data required to generate the same binary within code.
I am new to using batch so I'm not sure if what I'm trying to do is possible, BUT, the scenario is I have several switches that I need to manage using SSH. I am currently using plink(putty) to do so through the command prompt. I'm able to connect to my switches but I'm confused on how to automate the login portion.
What I'm trying to figure out is when I connect to the switch I am stopped 3 times and asked for input, one time for username, again for username(i dont know why its twice) and then finally for password. All of that before I can actually run commands on the switch.
So in my very archaic batch file I'm attempting to do the following.
echo
plink SESSIONNAME -l username -pw password
enable
config
crypto key generate rsa
the switch however doesn't want to cooperate with plink in accepting the input username and pw, instead prompting me to input that same information into cmdprompt. Is there a way in batch to have it "wait" for the switch to prompt me for the username and then input it, then "wait" for the switch to prompt me for the password and input that as well? All before executing my desired commands?
Every search I've done has only given me the results for the other way around, where the batch file would prompt the user for input, rather than whatever im connecting to prompting me for input.
Its possible I am just unaware of the proper terms to search for, if thats the case please let me know so I can redo my research. I'm just at a point where I'm not sure where to go or what to ask.
Plink log output
User Name:USERNAME
Password:PASSWORD
source#
Additional
Looking up host "X"
Connecting to X port 22
Server version: SSH-2.0-OpenSSH_3.4p1.RL
We believe remote version has SSH-2 channel request bug
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.66
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 2048 XXXXXXX
Initialised AES-256 CBC client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 CBC server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "USERNAME".
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
For anyone who might run into the same issue, I ended up needing to set up a linux box(ubuntu in my case) and then install expect, sudo apt-get install expect, then create a script working around that. The syntax is fairly simple, mine ended up similar to whats below. Links to useful resources I found are below that. To be more specific on the devices, they were Dell PowerConnect switches, ranging between series, 3400, 3500, and 6200.
#!/usr/bin/expect
spawn /usr/bin/plink -ssh HOST
expect -exact "User Name:"
send "USERNAME\r"
expect -exact "Password:"
send "PASSWORD\r"
send "whatevercommandsyouwant\r"
send "exit\r"
expect eof
Its not perfect but it drastically reduces the amount of time spent updating switches or gathering config info.
Debugging Expect
Expect Examples
I made a back-end server which redirects users who abuse the main server (via too many invalid webpage requests in a short time) to another port so that the load on the server will be slightly less.
I then in my program via a exec() issue this command to block the IP from regular service:
iptables -t nat -I <tableforport> -p tcp --src <offending ip> -j REDIRECT --to-port <port of my server>
The problem is when I test this using an actual 2-computer setup where one is the client spamming the server (I'm actually holding F5 down for a few minutes to test), The internal port redirection doesn't seem to kick in right away. If I pause from holding F5 down for a few minutes then try again, then the internal redirection works and the blocking message from my server software works.
I feel this is due to linux (which the server runs on) caching remote IP address entries along with its ports along with other instructions causing the new iptables rules (like the one above) to be skipped until the routing cache is flushed for that IP.
In linux, I can easily flush the routing cache for each IP version via:
echo 1 > /proc/sys/net/ipvn/route/flush
where n in ipvn is either a 4 or 6.
The problem with that is if I execute it, then all the good IP's in cache will be flushed which in turn creates a slower experience for all. I only want to create a bad experience to potential hackers.
How do I go about removing only one IP address from the route cache so that when I add a redirection rule to iptables (like above), the redirection takes place right away the moment the client refreshes the page (not several refreshes, seconds or minutes later)?
Once I get an answer, I want to be able to make a C program out of it after which I can probably figure out myself.
I want monitor my ntpd services and ntpd service is used udp protocol。nagios have a method that is named check_udp,As follows:
[root#localhost]# ./check_udp -H 127.0.0.1 -p 123
With UDP checks, a send/expect string must be specified.
I want to know how to use check_udp...
I suggest saving yourself some effort and use one of the many NTP nagios plugins like the one below from the official nagios plugins package.
http://nagiosplugins.org/man/check_ntp_peer