Mike,
you are close: you want the mysql client to give back just the data, no
column description. Change this line to read:
MYSQL=/usr/local/mysql/bin/mysql --user=$username --password=$password
--host=$server --skip-column-names cetechnology
On Tue, 10 Feb 2004, Mike Tuller wrote:
Ok. I
Ok. I think I am close to getting this. Here is what I have.
MYSQL=/usr/local/mysql/bin/mysql --user=$username --password=$password
--host=$server cetechnology
RESULT=$(echo select count(*) from hardware_assets where
ethernet_address='$ethernet_address' | $MYSQL)
if [ $RESULT = 0 ] ; then
Why do you keep changing the script?
Mike Tuller wrote:
Ok. I think I am close to getting this. Here is what I have.
MYSQL=/usr/local/mysql/bin/mysql --user=$username --password=$password
--host=$server cetechnology
RESULT=$(echo select count(*) from hardware_assets where
RESULT=`echo se;ect
Okay, the lack of locking was driving me crazy. Here's my
version:
#!/usr/bin/sh
MYSQL=mysql -v test
ethernet_address=$1
cat EOF | $MYSQL
LOCK TABLES hardware_assets WRITE;
SELECT @asset_id := asset_id
FROM hardware_assets WHERE ethernet_address = '$ethernet_address';
REPLACE INTO
You could create a User defined Function that contains this logic. At the
present time, an UDF needs to be coded in C.
Depending on how your `users` interface with the application, you could
write a C/C++ or java command line interface as well.
Original Message
On 2/9/04, 10:53:00 AM, Mike
IF works on the selections not on the query.
Select IF(lastname='clark','Correct',''Incorrect'), firstname from
namefile;
You need to do the checking in your script.
For example in bash:
RESULT=`echo select count(*) from manefile where lastname='clark' |
mysql database`
if [ $RESULT = 0 ] ;
If you are always updating the entire row you could delete the record
(ignoring failures) and then insert the record. Not efficient but it
would work.
If you are able to trap errors in your shell script and there is a
unique index on the ethernet_address field then you can do this:
Update
I changed my script to this:
/usr/local/mysql/bin/mysql --user=$username --password=$password
--host=$server
RESULT=`echo select count(*) from hardware_assets where
ethernet_address='$ethernet_address' | cetechnology'
if [ $RESULT = 0 ] ; then
echo INSERT INTO hardware_assets
Mike Tuller [EMAIL PROTECTED] wrote on 09/02/2004 16:53:00:
I have posted this question a few times, and have not seen the answer
that I
need.
I have a shell script, that gathers information from systems, and I want
that info to be entered into a database. I want it to check first to
This is NOT a script that can run under mysql.
It is a bash script that calls mysql.
MYSQL=/usr/local/mysql/bin/mysql --user=$username --password=$password
--host=$server cetechnology
RESULT=`echo select count(*) from hardware_assets where
ethernet_address='$ethernet_address' | $MYSQL
if [
When I run this, it always updates the record, not matter what the value for
$ethernet_address is. I have tested this by changing the line under else to
echo Update Every time the script is run, it comes back with update.
I then we back and commented out the whole if/else statement and had only
Try something like this:
MYSQLSTRING=/usr/local/mysql/bin/mysql -u $username -p $password -h $server
cetechnology
RESQUERY=SELECT COUNT(*) FROM hardware_assets WHERE
ethernet_address='$ethernet_address'
RESULT=`echo $RESQUERY; | $MYSQLSTRING`
INSERTQUERY=INSERT INTO hardware_assets
Ignore this as aparently someone already posted almost the exact same
thing :)
Thanks,
Ryan Yagatich
,_,
\ Ryan Yagatich [EMAIL PROTECTED] \
/ Pantek Incorporated (877) LINUX-FIX /
\
13 matches
Mail list logo