SH file

Any and all non-support discussions

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

SH file

Postby gmcust3 » Tue Jan 12, 2010 2:49 pm

I am have created a SH file.

In that I have a line

mysql -uroot -pvicipass

After this Line I want to execute few sql queries.

How to do that ?
GoAutoDial CE
VERSION: 2.4-309a
BUILD: 110430-1642
No other software installed on the box.
I've read the manager manual.
gmcust3
 
Posts: 1148
Joined: Sat Oct 24, 2009 1:15 pm

thanks

Postby brett05 » Tue Jan 12, 2010 3:06 pm

ok so you want to create a sh file that will be executed after
of say same sql queries you want then and i will help you .
or create you date base file .sql then call it as this for exemple .
mysql --user="user" --password="password" < /root/sample.sql
Jasperreports & Queuemetrics & SugarCRM integration - Customization and Add-ons
Freepbx||Billing||Centos||Opensuse||Debian||Centos||Fedora||Sangoma||Diguim
brett05
 
Posts: 571
Joined: Sun May 24, 2009 5:48 pm
Location: tunisia

Postby gmcust3 » Tue Jan 12, 2010 3:09 pm

ok so you want to create a sh file that will be executed after
of say same sql queries you want then and i will help you .


I am looking for this.
GoAutoDial CE
VERSION: 2.4-309a
BUILD: 110430-1642
No other software installed on the box.
I've read the manager manual.
gmcust3
 
Posts: 1148
Joined: Sat Oct 24, 2009 1:15 pm

Postby Michael_N » Tue Jan 12, 2010 4:37 pm

Enter your SQL syntax

Make the file executeble

Run it
Michael_N
 
Posts: 687
Joined: Wed Jul 05, 2006 3:13 pm
Location: sweden

Postby gmcust3 » Tue Jan 12, 2010 5:58 pm

An Example will definitely help.
GoAutoDial CE
VERSION: 2.4-309a
BUILD: 110430-1642
No other software installed on the box.
I've read the manager manual.
gmcust3
 
Posts: 1148
Joined: Sat Oct 24, 2009 1:15 pm

Postby Michael_N » Tue Jan 12, 2010 6:08 pm

Michael_N
 
Posts: 687
Joined: Wed Jul 05, 2006 3:13 pm
Location: sweden

Postby gmcust3 » Tue Jan 12, 2010 7:09 pm

This is what I am trying to do ..

Sql.sh:
======================
mysql -uroot -pvicidialnow
Use asterisk;
Insert Into ...... blah blah...
Insert Into ...... blah blah...
Insert Into ...... blah blah...
Insert Into ...... blah blah...
Insert Into ...... blah blah...
Update..... ...... blah blah...
Exit

I tried chmod +x switch. But it gets stuck after getting into mysql and after I enter EXIT, then it tries to run sql command.
GoAutoDial CE
VERSION: 2.4-309a
BUILD: 110430-1642
No other software installed on the box.
I've read the manager manual.
gmcust3
 
Posts: 1148
Joined: Sat Oct 24, 2009 1:15 pm

thanks

Postby brett05 » Tue Jan 12, 2010 9:36 pm

ok we will do a small exemple here:
first thing we will create a file sample.sh
we will write this:
#!/bin/bash
echo "welcome to our script"
echo "------------------------"
echo " drop database asterisk if exist"
mysql --user=cron --password=1234 --execute="DROP DATABASE IF EXISTS `asterisk`;"
echo "-----------------------"
echo "create asterisk database"
mysql --user=cron --password=1234 --execute="create database 'asterisk' default character set utf8 collate utf8_unicode_ci;
echo "---------------------------"
echo "use database asterisk"
mysql --user=cron --password=1234 --execute="use 'asterisk';"
echo "---------------------------"
echo" "create table mytable"
mysql --user=cron --password="CREATE TABLE 'mytable' (
'P_Id' int, 'LastName' varchar(255), 'FirstName' varchar(255), 'Address 'varchar(255), 'City' varchar(255) )"
echo "---------------------------"
echo "insert data in table mytable"
mysql --user=cron --password="INSERT INTO 'mytable' ('FirstName', 'Address', 'City') VALUES ('111', '222', '333');"
echo "---------------------------"
echo "bye bye"

then save your file sample.sh for exemple in /usr/local and run it
chmod 777 -R /usr/src/sample.sh
./usr/src/sample.sh

if they are same thing mistake please correct it :wink:
enjoy
Jasperreports & Queuemetrics & SugarCRM integration - Customization and Add-ons
Freepbx||Billing||Centos||Opensuse||Debian||Centos||Fedora||Sangoma||Diguim
brett05
 
Posts: 571
Joined: Sun May 24, 2009 5:48 pm
Location: tunisia

Postby gmcust3 » Tue Jan 12, 2010 9:54 pm

Perfect !!!

Awesome and Thanks { though thats spoon feeding }.

Here is the Updated and a BIT corrected :

#!/bin/bash
echo "Welcome to our script"
echo "------------------------"
mysql -uroot -pvicidialnow -e "use asterisk;CREATE TABLE mytable (P_Id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255))"
echo "---------------------------"
echo "insert data in table mytable"
mysql -uroot -pvicidialnow -e "use asterisk;INSERT INTO mytable(FirstName, Address, City) VALUES ('111', '222', '333')"
echo "---------------------------"
echo "bye bye"
GoAutoDial CE
VERSION: 2.4-309a
BUILD: 110430-1642
No other software installed on the box.
I've read the manager manual.
gmcust3
 
Posts: 1148
Joined: Sat Oct 24, 2009 1:15 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 21 guests