Ignore this as aparently someone already posted almost the exact same thing :)
Thanks, Ryan Yagatich ,_____________________________________________________, \ Ryan Yagatich [EMAIL PROTECTED] \ / Pantek Incorporated (877) LINUX-FIX / \ http://www.pantek.com/security (440) 519-1802 \ / Are your networks secure? Are you certain? / \___F49F3365CFC4F2613AD204C58E50C1AD73F23DC722666BD4___\ On Mon, 9 Feb 2004, Ryan Yagatich wrote: > >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 (ethernet_address) VALUES >($ethernet_address)" >UPDATEQUERY="UPDATE hardware_assets SET Operating_system='10.3.3'" >if [ $result -eq 0 ]; then > echo "$INSERTQUERY;" | $MYSQLSTRING >else > echo "$UPDATEQUERY;" | $MYSQLSTRING >fi > > >Thanks, >Ryan Yagatich > >,_____________________________________________________, >\ Ryan Yagatich [EMAIL PROTECTED] \ >/ Pantek Incorporated (877) LINUX-FIX / >\ http://www.pantek.com/security (440) 519-1802 \ >/ Are your networks secure? Are you certain? / >\___F49F3365CFC4F2613AD204C58E50C1AD73F23DC722666BD4___\ > >On Mon, 9 Feb 2004, Mike Tuller wrote: > >>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 (ethernet_address) VALUES >>($ethernet_address);" >>else >> echo "UPDATE hardware_assets SET operating_system='10.3.3';" >>fi >> >>Where cetechnology is the database. All the variables are set. >> >>When I run this, it starts the mysql client application, with the mysql> >>prompt. Nothing is inserted or updated in the database though. >> >>This is the same problem I had when I tried to do it this way, but I am not >>knowledgeable in shell scripting yet to know what I am doing wrong. >> >> >> >> >>> From: gerald_clark <[EMAIL PROTECTED]> >>> Date: Mon, 09 Feb 2004 11:11:24 -0600 >>> To: Mike Tuller <[EMAIL PROTECTED]> >>> Cc: MySql List <[EMAIL PROTECTED]> >>> Subject: Re: There has to be a way to do this >>> >>> 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" ] ; then >>> echo "insert into namefile ....... >>> else >>> echo "update namefile ...... >>> fi >>> >>> >>> Mike Tuller wrote: >>> >>>> 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 see if >>>> the data is already entered, and if not, add it. If it has already been >>>> entered, then update the record. >>>> >>>> I would think that some type of if/else statement would work, but I can't >>>> get the IF statement http://www.mysql.com/doc/en/IF_Statement.html to work >>>> correctly in MySql. >>>> >>>> Here is what I have: >>>> >>>> "IF SELECT * FROM hardware_assets WHERE ethernet_address='$ethernet_address' >>>> IS NULL\ >>>> THEN INSERT into hardware_assets (ethernet_address) VALUES >>>> ($ethernet_address)\ >>>> ELSE\ >>>> UPDATE hardware_assets SET operating_system='10.3.3'\ >>>> END IF;" >>>> >>>> I get back that I have an error in my SQL syntax. $ethernet_address is set, >>>> so that is not my problem. >>>> >>>> Does anyone know a way to go about this in SQL, or in a shell script? I >>>> don't want to do it in Perl or PHP. >>>> >>>> >>>> Thanks, >>>> Mike >>>> >>>> >>>> >>>> >>> >>> >>> >>> -- >>> MySQL General Mailing List >>> For list archives: http://lists.mysql.com/mysql >>> To unsubscribe: >>> http://lists.mysql.com/[EMAIL PROTECTED] >>> >> >> >> > > > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]