The Ping command uses an ICMP request as far as I know
So is it possible to send a short text with the ping command right from commandline?
What about ping -p pattern? Keep in mind that not all of versions of ping support -p option.
You may specify up to 16 ''pad'' bytes to fill out the packet you
send. This is useful for diagnosing data-dependent problems in a
network. For example, -p ff will cause the sent packet to be filled
with all ones.
E.g. ping -p 486920686572652e www.example.com, where 486920686572652e = Hi here.
#!/bin/python3
import sys, subprocess
text = sys.argv[1]
target = sys.argv[2]
if len(text)>16:
print("Text too long!")
exit()
enctext = r''.join( hex(ord(c)).split("x")[1] for c in text )
subprocess.check_output(["ping", "-p", enctext, "-c", "1", target])
Maybe this piece of code is helpful for somebody
Related
I have expect script that does backups.
It worked fine on different machines and OSes but it does not work on Ubuntu 12.04
#!/usr/bin/expect -f
set folder [lindex $argv 0]
set password "PassWD"
spawn mysqldump -u root -p mydb01 --result-file=/home/myuser/backup/$folder/$
expect "*assword:"
send "$password\n";
#interact
wait
I tried to change expect line to
expect "Enter password:"
or
expect "Enter password: "
It does not work and it asks me to enter password like
Enter password:
I checked that mysql password is correct.
That script worked fine since 2010 on different OSes.
UPDATE
I created another cloud server with same OS and same data.
Everything works there. I have no idea why it does not work on first one.
I guess servers may have old commodity harddrives and it corrupted some file.
Can you try like this,
expect "password"
or
expect -re ".*word"
Please make sure you are using the switch '-re' with expect when you want to use regular expressions.
I know there are many mysql-proxy questions on SO, however I have read through many of them and none seem to solve my problem. I am simply trying to get mysql-proxy up and running, with the eventual purpose of rewriting some queries that go through the proxy. I am using ubuntu 14.04, I have mysql-proxy version 0.8.1, and mysql version 5.5.37. To start mysql-proxy I run the following line on the command line
sudo mysql-proxy --defaults-file=mysql-proxy.cnf
where the file mysql-proxy.cnf looks like the following:
[mysql-proxy]
log-file= /var/log/mysql/proxy-error.log
log-level= debug
admin-lua-script= /usr/lib/mysql-proxy/lua/admin.lua
proxy-lua-script= /path/to/lua/script/example.lua
admin-username = myusername
admin-password = mypassword
proxy-skip-profiling = true
proxy-address = localhost:4040
proxy-backend-addresses = localhost:3306
plugins = proxy,admin
My example.lua script is very simple, and meant only to verify that the mysql-proxy query is being altered. example.lua is pasted below
-- first_example.lua
function read_query(packet)
if string.byte(packet) == proxy.COM_QUERY then
print("Hello world! Seen the query: " .. string.sub(packet, 2))
end
end
Since I don't run this with the --daemon flag, when I run that line above in the command line it just loops indefinitely, which is expected.
Finally, in separate terminal session, I run the following on the command line and enter my password in order to connect with the proxy
mysql -u myusername -p -h localhost -P 4040
I then select a database to use, and run a simple SELECT query on one of the tables. Based on multiple articles/tutorials I've read on mysql-proxy, my first console session, the one that ran mysql-proxy, should print out some data based on the example.lua file. However this does not happen, in fact nothing happens.
I'm not sure if the following bit of information makes any difference, but in my "my.cnf" mysql configuration file, I have these couple of lines
bind-address = 255.255.255.255
#bind-address = 127.0.0.1
where I have replaced my actual ip address with 255.255.255.255 because I do not want to display my ip address publicly.
Please, I have been trying to figure this out for several days, and no amount of new lua scripts, or changing the host:port parameters in the mysql-proxy.cnf file have solved anything. I
//update: when feeding mysql passwords, -ppassword works. -p password does -not- work. Problem solved.//
We have hundreds of databases on our work servers, and I'd like to write a ruby script that automates the process of creating duplicate versions of them on my local machine for development purposes.
I've been trying to use net-ssh to create the tunnel, but (host, user, pass, etc. are censored for obvious reasons):
require 'net/ssh'
HOST = 'xxx'
USER = 'yyy'
PASS = 'ppp'
Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
puts "inside ssh tunnel"
puts ssh.exec!('ruby -v')
puts ssh.exec!('mysql -u zzz -p pswrd -h c3 will_il_raw -e "select * from deeds limit 1"')
end
results in the output:
inside ssh tunnel
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
followed by an indefinite hang. Interestingly, if I ssh into the same computer via the console, 'ruby -v' returns 1.9.3. If I enter that mysql query there, it successfully returns one line of the named table.
I assume the solution has something to do with port forwarding, but here my limited knowledge begins to fail me utterly.
The machine running the mysql server is not the same machine as I am accessing it from, which is not, in turn, the machine I am actually sitting at. I need to connect the dots and apparently have no idea how to go about this properly.
Any protips would be much appreciated.
In MySQL syntax, when feeding a password using -p[password], there is no space between -p and the password.
Because the script's version of the syntax had a space, the result of the query was a prompt requesting the password, which caused the hang on the far end of the SSH tunnel.
I'm looking for a kind of remote database backup automation.
Then, I came across a scripting language which commonly used for administrative tasks, "Expect scripting" and I believe it could serve my purpose very well.
what I'd like to do is I want to perform login to a remote server using the following bash script from my local linux box. (supposed everything has been set properly, SSH authentication via generated key pair, so no password is required)
For the most important part, I'd like to send a mysqldump command to perform backup for my database on that server.
#!/usr/bin/expect
set login "root"
set addr "192.168.1.1"
spawn ssh $login#$addr
expect "#"
send "cd /tmp\r"
expect "#"
send "mysqldump -u root -ppassword my_database > my_database.sql\r"
expect "#"
send "exit\r"
The only problem I found here was after the line send "mysqldump -u root....... ".
It was never waiting until the process to finish, but immediately exit the shell with 'send "exit\r"' command line.
what do I do to make it waits until mysqldump command finish and log off the SSH properly?
I don't know the answer to your question: add exp_internal 1 to the top of the program to see what's going on.
However, since you have ssh keys set up, you don't really need expect at all:
ssh $login#$addr 'cd /tmp && mysqldump -u root -ppassword my_database > my_database.sql'
Mysql client is behaving strangely on one of my servers.
I have my mysql server (ip 10.0.0.190, used to be 172.16.0.190).
I have another server from which I try to connect, which I will refer to as collab.
Bind address is set to 0.0.0.0 server-side, as well as the Grant options for collab.
When I try to connect through mysql-client, here is what I do :
> mysql -u user -p -h mysql.domain
This doesn't work, and after 30s I get this error message :
ERROR 2003 (HY000): Can't connect to MySQL server on 'mysql.domain' (110)
Now the weird thing is that if I do :
> mysql -u user -p -h 10.0.0.190
Everything works correctly. At first, I thought it was a DNS issue, so I tried ping, dig which all answered properly. ie, from client :
> ping mysql.domain
64 bytes from mysql.domain (10.0.0.190): icmp_req=1 ttl=64 time=0.999 ms
So I launched tcpdump on both the server and the client. On the server I get nothing.
On the client :
> tcpdump port 3306
[ ... ]
11:11:41.139499 IP client.domain.49186 > 172.16.0.190.mysql
[ ... ]
As I said, 172.16.0.190 used to be the client's IP before I switched my network. I understand this is where the error comes from, but I can't figure out how to solve it.
Obviously the error comes from the collab but I can't figure out where does it comes from. I've tried to grep '172.16.0' in my /etc on collab in case I had forgotten anything, but nothing came back.
Moreover, when I try to connect from another server using the FQDM, it works.
Anyone has an idea ?
Thanks,
Cheers
H
this may be a DNS cache issue. Try flushing your cache. If you are on windows/osx, look at this: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/ClearingBrowserCache
I'm not sure what has to be done on Linux.
(Flush on CLIENT side, by the way).