nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

get data mysql from shell

This is a discussion on get data mysql from shell within the Shell scripting forums, part of the Development/Scripting category; dear all, would u help me to get data from mysq from shell scripting? my scripts is: ################################### SQL_HOST=localhost SQL_USER=myuser ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 05-09-2007, 09:56 AM
Junior Member
User
 
Join Date: May 2007
Posts: 1
Rep Power: 0
alpa is on a distinguished road
Default get data mysql from shell

dear all,

would u help me to get data from mysq from shell scripting?
my scripts is:

###################################
SQL_HOST=localhost
SQL_USER=myuser
SQL_PASSWORD=mypassword
SQL_DATABASE=my db

MEDIA=1

DATE=`date +"%Y-%m-%d %H:%M:%S"`
FROM=`formail -zx From: < $2 | sed 's/"//g'`
TO=`formail -zx To: < $2`
SUBJECT=`formail -zx Subject: < $2`
SENT=`formail -zx Sent: < $2`
TEXT=`formail -I "" <$2`

if [ "$SQL_PASSWORD" != "" ]; then
SQL_ARGS="-p$SQL_PASSWORD";
else
SQL_ARGS="";
fi
SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"

#KEY CODE
reg=`echo "${TEXT}" | tr [A-Z] [a-z]`
array=(${reg:0})


#GET ACTIVED REGISTRATION
getData=`/usr/bin/mysql $SQL_ARGS "SELECT key FROM key_table WHERE status=\"0\" AND media=\"$MEDIA\";"`

if [ "$getData" = "${array[0]}" ]; then

/usr/bin/mysql $SQL_ARGS "UPDATE phonebook SET Name=\"${array[1]}\" WHERE msisdn=\"$FROM\";"
elif [ "$getData" != "${array[0]}" ]; then

/usr/bin/mysql $SQL_ARGS "INSERT INTO phonebook (msisdn,DateIn,media)
values (\"$FROM\",\"$DATE\",\"$MEDIA\");";
fi

################################################

i can't get my data from $getData like Key Code?
it must use mysql_fetch_assoc or the others?
where the problem is?
please help me.

best regards.

Tomi
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-14-2007, 07:02 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Debug script running command

Code:
bash –x script
bash –x –v script
On a second thought you might try php and call php script from cron job. This is the recommended way to schedule mysql related jobs
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
MYSQL master-master replication monitor shell script zafar466 Databases servers 2 07-12-2008 01:26 PM
Parse XML file and store data in array in shell scripting Nishanthhampali Shell scripting 5 02-14-2008 12:57 PM
Backup mysql from shell prompt or script raj Linux software 0 07-30-2006 12:17 AM
Script for accessing data .. Dastard Shell scripting 1 07-26-2006 12:12 AM
print data to txt rock Shell scripting 1 03-10-2006 03:01 AM


All times are GMT +5.5. The time now is 06:57 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36