I've been trying to get an OpenVPN server running Debian-7-Wheezy to authenticate via mySQL all day. I have mySQL hosted on another server running WHM and cPanel. I added the OpenVPN server's IP to the whitelist for database connections, checked all my credentials and double checked the config file. When I run: /etc/openvpn/script/test_connect_db.sh test 1234 I recieve this error:
/etc/openvpn/script/test_connect_db.sh: line 6: mysql: command not found
authentication failed.
The file located at: /etc/openvpn/script/test_connect_db.sh looks exactly like this:
#!/bin/bash
. /etc/openvpn/script/config.sh
##Test Authentication
username=$1
password=$2
user_id=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "select user_id from user where user_id = '$username' AND user_pass = '$password' AND user_enable=1 AND user_start_date != user_end_date AND TO_DAYS(now()) >= TO_DAYS(user_start_date) AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date='0000-00-00')")
##Check user
[ "$user_id" != '' ] && [ "$user_id" = "$username" ] && echo "user : $username" && echo 'authentication ok.' && exit 0 || echo 'authentication failed.'; exit 1
Any idea what's wrong?
It sounds like you aren't event getting far enough to attempt a mysql connection to begin with.
The error you specified indicated it can't even find the mysql client.
Can you successfully just run "mysql" from the command line outside the script?
If so that would indicate your $PATH variable isn't set properly in scope of the script.
You didn't say what config.sh is doing. Maybe that's over writing the PATH variable?
Either way if you can run mysql from the command line then run
which mysql
That should give you the fully qualified path to the client binary and you could use that in your script.
Related
I am experiencing an issue with our Zabbix monitoring (Zabbix server 5) running on CentOS7. The Zabbix agent executes user parameter which includes sql query and getting a result from Production DB. The structure of the user parameter is the same as the other alerts (only the SQL queries are different) and some of them are working fine, others don't work at all. The error I was first receiving was about missing ORACLE_HOME dir as environmental variable.
"Error 6 initializing SQL*Plus SP2-0667: Message file sp1.msb
not found SP2-0750: You may need to set ORACLE_HOME to your Oracle
software directory"
So I added the ORACLE_HOME directory for the Zabbix user and when I ask Zabbix agent to execute "zabbix_agentd -t userparameter-name" I am receiving the desired result.
Unfortunately, when I test the item (alert) in Zabbix server UI, it still returns me the old error for ORACLE_HOME.
I tried to clear the configuration cache on both - Zabbix server and Proxy but there wasn't positive result. The restart of Zabbix server, proxy or agent didn't worked as well.
Here is how the user parameter looks like:
echo -e "set feed off\n set pages 0\n set head off\n set space 0\n set heading off\n SELECT count(uuid) FROM prodlive.task WHERE tasktypeid = 'SWU_EMAIL_PROCESSING' AND status = 'PENDING' AND NEXTSCANTIME <= (SYS_EXTRACT_UTC(SYSTIMESTAMP) - (5/(24*60)));"|sudo -i -u zabbix /opt/oracle/product/11.2/client/bin/sqlplus -s <USERNAME>/<PASSWORD>'(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <HOSTNAME>)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = <SERVICE-NAME>)))'| awk '{print $1}'
The structure of the user parameter works fine on other alerts running on this server, but for some unknown reason, for some of the alerts, its not working. All SQL queries were tested and validated before adding them in Zabbix monitoring.
Here is the structure of the user parameter used for running SQL queries against Oracle SQL DB.
echo -e "set feed off\n set pages 0\n set head off\n set space 0\n set heading off\n <SELECT STATEMENT GOES HERE>"|sudo -i -u zabbix /opt/oracle/product/11.2/client/bin/sqlplus -s <USERNAME>/<PASSWORD>'(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <name-of-the-host>)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = <SERVICE-NAME>)))'| awk '{print $1}'
If someone could give me advice how to fix this issue, will be very grateful.
I'm planning to use Temple MySQL
to monitor MySQL detail instances. Unfortunatelly I can't get result. What am I still missing in configuration. Check it out zabbix-agent log those are piece of log not the whole log.
XECUTE_STR() command:'/usr/lib/zabbix/externalscripts/mysql_check.pl' len:0 cmd_result:''
28786:20160121:141008.072 Sending back []
28786:20160121:141008.072 listener #2 [waiting for connection]
28788:20160121:141008.648 In send_buffer() host:'127.0.0.1' port:10051 values:0/100
28788:20160121:141008.648 End of send_buffer():SUCCEED
28788:20160121:141008.648 active checks #1 [idle 1 sec]
28784:20160121:141008.795 collector [processing data]
28784:20160121:141008.796 In update_cpustats()
28784:20160121:141008.796 End of update_cpustats()
28784:20160121:141008.796 collector [idle 1 sec]
28785:20160121:141009.075 listener #1 [processing request]
28785:20160121:141009.075 Requested [mysql[root,Qwestions,lld]]
1. Add special user for MySQL:
example:
GRANT USAGE ON *.* TO 'zabbix'#'%' IDENTIFIED BY 'superpassword';
FLUSH PRIVILEGES;
2. Add user params into zabbix-agent configuration
Edit /etc/zabbix/zabbix_agentd.conf
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}'
UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/etc/zabbix mysql -N
if you want to extend monitoring items just add another UserParameter with proper SQL-query
3. Add auth-file for MySQL:
create .my.cnf file into /etc/zabbix/
[client]
user = zabbix
password = superpassword
4. Restart agent (and zabbix-proxy if you use it)
Log is useless. We see only script returns no result and can't see why.
Try to connect to MySQL from console using credentials that you provided in mysql_check.pl file. Be sure that user have enough permissions (SUPER at last).
mysql -hhostname -uuser -ppassword
Run script from user zabbix and check result:
perl ./mysql_check.pl
I had written a script that connects to the local mysql server every 6 seconds and checks if there is any data in the table .if there is data it runs some php commands and then deletes that data from the table. I logged into my remote server(Shared hosting) through ssh and then copied the script and executed it using command "nohup ./script.sh 0<&- &>alert.log &" so that it runs in background and writes all the output to alert.log file. my problem is that when i log in to the server through SSH and execute the script it runs perfectly , but when i log out from server its not running . when i check the alert.log file after it is showing error "cannot connect to local mysql server". any solutions ??
this is the code
while true
do
res=($(mysql -u root -p123456 --skip-column-names -Dtest -e "select id from temptab"))
if [[ "$res" > 0 ]];then
del=`mysql -u root -p123456 -Dtest -e "delete from temptab;" `
now="$(date +'%d/%m/%Y:%H.%M.%S')"
for ((i=0; i < ${#res[#]}; i++))
do
php -n /var/lib/mysql/trigger.php ${res[$i]}
echo "[$now]:Trigger called with videoid ${res[$i]}"
done
fi
sleep 6
done
and this is the sample output
cat nohup.out
X-Powered-By: PHP/5.4.20
Content-type: text/html
{"multicast_id":8864856209398719411,"success":2,"failure":1,"canonical_ids":0,"results":[{"message_id":"0:1385797766832904%4f0c6467f9fd7ecd"},{"error":"InvalidRegistration"},{"message_id":"0:1385797766832901%4f0c6467f9fd7ecd"}]}81Inserted police info
[30/11/2013:00.49.26]:Trigger called with videoid 65
/etc/bashrc: line 14: whoami: command not found
/etc/bashrc: line 20: grep: command not found
/etc/bashrc: line 59: dircolors: command not found
./alert.sh: line 15: php: command not found
[30/11/2013:07.50.27]:Trigger called with videoid 70
./alert.sh: line 15: /ramdisk/php/54/bin/php54: No such file or directory
[30/11/2013:09.09.52]:Trigger called with videoid 71
screen is what you need. There are plenty of tutorials on google on screen usage.
I suggest to move your code into a crontab even that will run every X minutes (5 minutes, or anything else you like) rather than have your user run it during a live session.
Just place the PHP script inside a call to cron, login, and run crontab -e then add:
*/5 * * * * /home/username/phpscript.php
You could try to run your script like:
/path/to/script.sh </dev/null &>/home/yourname/alert.log &
disown
I
finally i got the solution .... i was using /usr/bin/php to call my php files but .....when i edited it to /usr/bin/php.orig it started working........... but what is that php.orig...?? #all thanks
How can I authenticate a valid user already registered on mysql automatically ? (Can be a batchscript, or vbs or anything that run automatically from windows) and if the user exist and the password is correct, call another batch ?
You could login with the command line client like so
mysql -uroot -ppassword -e"exit" && SET validlogin=true || SET validlogin=false
IF %validlogin% == true (ECHO run batch here) ELSE (ECHO don't run batch)
Some dos guru could probably do better
How can I check the mysql connection for a user/password using batch/shell script?
I've user name and password, and I need to authenticate whether they are correct or not, but how?
I tried this way:
I've created a batch file "run.bat" with "mysql -u User--password=UserPassword < commands.sql"
"commands.sql" file contains "\q"
When I run the file "run.bat" the output is nothing when User/Password are correct and "ERROR 1045 (28000): Access denied for user ... " when User/Password are incorrect. Now can we capture this output, and decide whether the connection is successful or not, if yes how?
Regards
I found a solution as below:
#echo OFF
echo \q | mysql -u User --password=UserPassword 2>nul
if "%ERRORLEVEL%" == "0" (
echo CONNECTION SUCCESSFUL
) else (
echo CONNECTION FAILED
)
You can check the return status of mysql. It is stored in the ERRORLEVEL enviroment variable:
mysql -u User--password=UserPassword < commands.sql
if "%ERRORLEVEL%" EQU "0" (
echo OK
) else (
echo FAIL
)
If you are lucky, mysql.exe even returns a specific status for "logon failed" that you can react on. Most applications return 0 on success and something != 0 on failure. Use echo %ERRORLEVEL% right after a command to find out the current value.
A more advanced approach would be to capture and evaluate the STDERR stream of the application. This, however, would be material for a different question.
you could use a ".my.cnf" file
I do this, although id strongly recommend against using your mysql root login
[root#daaorc900c ~]# cat ./.my.cnf
[client]
user=monitoruser
password=whatismonitor
[root#daaorc900c ~]#
Looks like you might be one windows so here is the doc for the "options files" in widnows
http://dev.mysql.com/doc/refman/5.1/en/option-files.html