LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-28-2006, 05:32 AM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
adding data to mysql database ?


is it possible for bash to connect to a remote dbase and enter details from users inputs to it

the script i have that wish to add data to database is this

Code:
#!/bin/bash

ip=`cat /etc/sysconfig/network-scripts/ifcfg-eth0|grep IPADDR|head -n1|cut -d'=' -f2`

echo "enter name"
read name
echo

echo "Enter Contact Address"
read letter
echo

echo "Please enter date Payment is due on"
read date
echo

echo "Please enter day of month to send Reminder"
read day
echo

echo "0 20 $day * * /home/archive/mailshot/sendmail -f sales@blah.co.uk -t "$letter" -m "Please be aware that payment for your server is due to us by the $date of this month" -u "$name Server Payment Due"" > /home/archive/mailshot/1.txt
echo "0 20 $day * * /home/archive/mailshot/sendmail -f sales@blah.co.uk -t "jerry@blah.co.uk" -m "$name on box $ip are due a payment by the $date of this month" -u "$name Server Payment Due"" > /home/archive/mailshot/mailshot/2.txt
echo "0 20 $day * * /home/archive/mailshot/sendmail -f sales@blah.co.uk -t "phil@blah.co.uk" -m "$name on box $ip are due a payment by the $date of this month" -u "$name Server Payment Due"" > /home/archive/mailshot/3.txt
echo "0 20 $day * * /home/archive/mailshot/sendmail -f sales@blah.co.uk -t "richie@blah.co.uk" -m "$name on box $ip are due a payment by the $date of this month" -u "$name Server Payment Due"" > /home/archive/mailshot/4.txt

a=`cat /home/archive/mailshot/1.txt`
b=`cat /home/archive/mailshot/2.txt`
c=`cat /home/archive/mailshot/3.txt`
d=`cat /home/archive/mailshot/4.txt`
z=`cat /home/archive/mailshot/mail.cron`

# make Filedescriptor(FD) 6 a copy of stdout (FD 1)
exec 6>&1

# open file "cron.txt" for writing
exec 1>/home/archive/mailshot/mail.cron

# produce some content
echo "$z"
echo "$a"
echo "$b"
echo "$c"
echo "$d"

# close file "mail.cron"
exec 1>&-

# make stdout a copy of FD 6 (reset stdout)
exec 1>&6

# close FD6
exec 6>&-

# make Filedescriptor(FD) 6 a copy of stdout (FD 1)
exec 6>&1

y=`cat /home/archive/mailshot/name.txt`

# open file "name.txt" for writing
exec 1>/home/archive/mailshot/name.txt

# produce some content
echo "$y"
echo "$name"

# close file "name.txt"
exec 1>&-

# make stdout a copy of FD 6 (reset stdout)
exec 1>&6

# close FD6
exec 6>&-

sed /^$/d mail.cron > mail1.cron
rm -rf mail.cron
mv mail1.cron mail.cron

crontab /home/archive/mailshot/mail.cron

rm -rf /home/archive/mailshot/1.txt
rm -rf /home/archive/mailshot/2.txt
rm -rf /home/archive/mailshot/3.txt
rm -rf /home/archive/mailshot/4.txt

exit 0

so it would add the clan contact address and repayment date

then if person was to end contract i have a scipt to remove the email reminder but would also like to connect to the dbase and remove details .

thanks in advance
 
Old 01-30-2006, 04:30 AM   #2
ebonhand
LQ Newbie
 
Registered: Jan 2006
Location: Australia
Distribution: Linux From Scratch
Posts: 6

Rep: Reputation: 0
Hmm.. I'm no guru, but I'm pretty sure you could cat into existence a file containing the required sql statements, and then pass the file to mysql using a command-line similar to:

Code:
mysql -uuser -ppassword db_name <sqlstatements.sql
Hope this helps!

- Ebonhand
 
Old 01-30-2006, 04:53 AM   #3
smurff
Member
 
Registered: Sep 2004
Location: England
Distribution: Mandriva 2005LE / Whitebox
Posts: 48

Rep: Reputation: 15
rharris, I cant help but I just wanted to say, nice script
 
Old 01-30-2006, 05:36 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by smurff
rharris, I cant help but I just wanted to say, nice script
????



Multiple echos instead of <<HERE documents, multiple hardcoded parameter strings.
Hardcoded directory paths?
It's one of those that develops into a hard to maintain
megascipt
 
Old 01-30-2006, 06:30 AM   #5
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Original Poster
Rep: Reputation: 15
please remeber i am new to linux so still learning

billy is it poss to connect to a remote database not on server to enter the info gathered into it

and then if client removes themselves from mailing i can delete database enteries ?

thanks in advance
 
Old 01-30-2006, 07:35 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
sorry, i really wasn't trying to be rude

remote database? Sure I should imagine so.
Most databases are on remote machines when you connect.
What sort of database?
You need to look at the DBMS software documentation
that should tell you how to do it.

I can't remeber a lot as I haven't done much with databases for a while (praise the lord!)
 
Old 01-30-2006, 03:07 PM   #7
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Original Poster
Rep: Reputation: 15
billy i wasnt being funny im just keen to learn and all help is greatly recieved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need to get data from xml file to MySQL database, and then use php to access Armon Linux - General 1 01-18-2006 02:54 PM
software for adding cddb information into a local mysql database jacksonscottsly Linux - Software 1 07-09-2004 09:21 PM
MYSQL Adding Data Ronw Linux - Software 3 04-13-2004 02:08 PM
pulling data from mysql database zuessh Linux - Software 5 05-29-2003 09:13 AM
Manage data and maintenance of MySQL database online rhuser Linux - Software 2 02-17-2003 08:31 PM


All times are GMT -5. The time now is 03:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration