Why does ejabberdctl not give a response for the check_password command? - ejabberd

I would like to use the command "ejabberdctl check_password user host password" but it does not respond. Why is this? I can use ejabberdctl to register a user, change a password, list users by host, but when I try to use the "check_password" command, there is no response on my command line. Is there a config setting I must update for this command to show a true or false response?

but it does not respond. Why is this?
As mentioned in its definition, that command returns a code:
$ ejabberdctl help check_password
Command Name: check_password
Arguments: user::binary
host::binary
password::binary
Returns: res::rescode
Tags: accounts
Description: Check if a password is correct
How to see the code? One way:
$ ejabberdctl check_password user1 localhost mypass11
$ echo $?
0
$ ejabberdctl check_password user1 localhost thisiswrong
$ echo $?
1

Related

login openshift with kubadmin fail: Login failed (401 Unauthorized)

As per offical documentation by Openshift , we can get kubadmin password as below:
crc console --credentials
To login as a regular user, run 'oc login -u developer -p developer https://api.crc.testing:6443'.
To login as an admin, run 'oc login -u kubeadmin -p gALwE-jY6p9-poc9U-gRcdu https://api.crc.testing:6443'
However , I can login successfully with developer/developer .kubeadmin will fail with "Login failed (401 Unauthorized)" . Restart CRC muiltiple times . Still not works ... Any idea about this ?
$ oc login -u developer -p developer https://api.crc.testing:6443
Login successful.
You have one project on this server: "demo"
Using project "demo"
$ oc login -u kubeadmin -p gALwE-jY6p9-poc9U-gRcdu https://api.crc.testing:6443
Login failed (401 Unauthorized)
Verify you have provided correct credentials.
Any inputs will be appreciated . Thanks in advance..
You said you restarted CRC. Have you tried deleting and recreating the cluster?
One of the first steps in productionizing a cluster is to remove the kubeadmin account - is it possible that you've done that and the "crc console --credentials" is now only displaying what it used to be?
If you have another admin account try:
$ oc get -n kube-system secret kubeadmin
The step to remove that account (see: https://docs.openshift.com/container-platform/4.9/authentication/remove-kubeadmin.html) is to simply delete that secret. If you've done that at some point in this cluster's history you'll either need to use your other admin accounts in place of kubeadmin, or recreate the CRC instance (crc stop; crc delete; crc setup)
Just in case others are having this issue and the issue persists even after trying crc stop, crc delete, crc cleanup, crc setup, crc start, I was able to sign in as kubeadmin by NOT using the following command after crc start got my CodeReady Container up and running.
eval $(crc oc-env)
Instead, I issue the crc oc-env command. In this example that the output returns /home/john.doe/.crc/bin/oc.
~]$ crc oc-env
export PATH="/home/john.doe/.crc/bin/oc:$PATH"
# Run this command to configure your shell:
# eval $(crc oc-env)
I then list the contents of the /home/john.doe/.crc/bin/oc directory which shows that the /home/john.doe/.crc/bin/oc directory is symbolically linked to the /home/john.doe/.crc/cache/crc_libvirt__amd64/oc file.
~]$ ll /home/john.doe/.crc/bin/oc
lrwxrwxrwx. 1 john.doe john.doe 61 Jun 8 20:27 oc -> /home/john.doe/.crc/cache/crc_libvirt_4.10.12_amd64/oc
And I was then able to sign in using the absolute path to the oc command line tool.
~]$ /home/john.doe/.crc/cache/crc_libvirt_4.10.12_amd64/oc login -u kubeadmin -p 28Fwr-Znmfb-V6ySF-zUu29 https://api.crc.testing:6443
Login successful.
I'm sure I could dig a bit more into this, checking the contents of my users $PATH, but suffice to say, this at least is a work around for me that gets me to be able to sign in as kubeadmin.

How to set mysql password automatically in bash script?

I have a bash script that opens queries from MySQL.
For example:
$ cat script.sh
mysql -u joe -D database -p ........ < first_query.sql
mysql -u joe -D database -p ........ < second_query.sql
This 2 lines inside my script.sh file return the results of the queries, but: Everytime I call the ‘mysql’ command, if it has the «-p» option, it asks for password TWICE (because I call mysql twice). How can I avoid this behavior?
I have tried passing my password as parameter, for example:
$ sh script.sh ‘mypassword’
and storing it in a variable and putting it after the «-p» option.
But it still asks for the password twice.
You can place your password staight after the -p. If you password is "123asd", the command will be:
mysql -u user -p123asd
Make sure there are no spaces between -p and your password.
Probably the simplest way would be to edit your my.cnf (found in /etc/mysql/ by default) to include your password, like so:
[client]
user = joe
password = ......

How to pass login parameters to mysql

I have a shell script which calls the mysql command line client, it looks like this:
$ cat ms
mysql --host=titanic --user=fred --password="foobar"
It works OK:
$ ./ms
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 810
...
Now, I'd like to keep the script in a git repository, but without the user and password details. So, I thought I would have a file SECRET with: --host=titanic --user=fred --password="foobar" which I wouldn't add to the git repository, and change the ms script like this:
mysql $(cat SECRET)
Unfortunately, it doesn't work. I get this error when I run it:
$ ./ms
ERROR 1045 (28000): Access denied for user 'fred'#'example.com' (using password: YES)
I cannot understand it - when the $(cat SECRET) is evaluated/expanded it looks exactly the same as the straightforward invocation of mysql. Still, it doesn't work. The same happens if I try to do it directly in interactive shell:
$ mysql --host=titanic --user=fred --password="foobar"
works OK, but the below does not:
$ cat SECRET
--host=titanic --user=fred --password="foobar"
$ mysql $(cat SECRET)
ERROR 1045 (28000): Access denied for user 'fred'#'example.com' (using password: YES)
$ echo mysql $(cat SECRET)
mysql --host=titanic --user=fred --password="foobar"
Anybody can shed some light on what's going on here and how to fix it? Many thanks in advance.
Change the file to:
--host=titanic --user=fred --password=foobar
Quotes aren't processed on the result of command or variable substitution, only word splitting and filename expansion are done.
But a better solution would probably be to use an option file, e.g. mysecret.cnf:
[mysql]
user=fred
password=foobar
host=titanic
Then run mysql as:
mysql --defaults-file=mysecret.cnf

execute mysql on remote server via bash script

I need to execute a mysql command on a remote server but seem to be hitting problem when it comes to executing the actual mysql bit
#!/usr/bin/expect -f
spawn /usr/bin/ssh -t root#10.0.0.2
expect "password: "
sleep 1
send "password\r"
sleep 2
/usr/bin/mysql databasename -e "update device_log set status = 'Y' where device_id in ('1','2');"
basically I want to change the flag to Y on device id's 1&2
but the script outputs
invalid command name "/usr/bin/mysql"
Just append the mysql command to the ssh command to run it in one go, like this:
#!/usr/bin/expect -f
spawn /usr/bin/ssh -t root#10.0.0.2 /usr/bin/mysql databasename -e "the query"
expect "password: "
sleep 1
send "password\r"
I'm not very much into expect, but I'm expecting that your attempt in the mysql line isn't actually valid syntax for expect to run a command.
Additionally:
You should use SSH keys for passwordless login instead of having a root password hardcoded in a script.
Consider running MySQL remotely e.g. mysql -h 10.0.0.2 -e "the query", or
Use port forwarding in SSH to connect to MySQL securely, e.g. run ssh -L 3307:localhost:3306 root#10.0.0.2 in the background and then connect to TCP port 3307 on localhost mysql -h 127.0.0.1 -P 3307.
It sounds like /usr/bin/mysql is not the the path to the mysql binary on that remote server. You could use just mysql instead, assuming that the binary is somewhere in that remote server's PATH. Otherwise you will have to go and find out where the binary is actually located and alter the absolute path accordingly.

mysql create database and user script

Question Rewritten:
HOMEDIR="ftpuser"
REMOTEIP="1.1.1.1"
MYSQLPASS="password"
Q1="DROP USER "$HOMEDIR"_shop;"
Q2="DROP DATABASE "$HOMEDIR"_shop;"
Q3="CREATE DATABASE IF NOT EXISTS "$HOMEDIR"_shop;"
Q4="GRANT ALL ON "$HOMEDIR"_shop TO '"$HOMEDIR"_shop'#'localhost' IDENTIFIED BY '$MYSQLPASS';"
Q5="GRANT ALL ON "$HOMEDIR"_shop TO '"$HOMEDIR"_shop'#'anotherip' IDENTIFIED BY '$MYSQLPASS';"
# Need to grant permissions from another server as well
Q6="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}${Q5}${Q6}"
echo $SQL
echo " "
ssh -p 8899 root#$REMOTEIP "mysql -u root -p "$SQL""
I then run:
/root/testing/migratesite.sh
And get:
bash: DROP: command not found
bash: CREATE: command not found
bash: GRANT: command not found
bash: GRANT: command not found
bash: FLUSH: command not found
What am I missing?
You are missing quotes and a proper mysql client command line:
ssh -p 8899 root#$REMOTEIP "mysql -u root -p -e \"$SQL\""
You need to escape the quotes around the $SQL variable so they get passed to the remote shell, else they get interpreted by the local shell (that's why you get DROP: command not found, the semi colon is interpreted by the shell.) Also, to have the mysql client to execute a command you have to pass the -e command line option.
Did you try this:
ssh -p 8899 root#$REMOTEIP "echo \"$SQL\" | mysql -u root --password=$SQL_PASS"