Inserting script variables into database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting script variables into database
# 1  
Old 11-30-2016
Inserting script variables into database

I have a script working out ink percentages
Code:
#!/bin/bash
currentcyan=$'iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER: 990'
currentmagenta=$'iso.3.6.1.2.1.43.11.1.1.9.1.2 = INTEGER: 972'
currentyellow=$'iso.3.6.1.2.1.43.11.1.1.9.1.3 = INTEGER: 972'
currentblack=$'iso.3.6.1.2.1.43.11.1.1.9.1.4 = INTEGER: 250'
maxcyan=$'iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER: 2800'
maxmagenta=$'iso.3.6.1.2.1.43.11.1.1.8.1.2 = INTEGER: 1800'
maxyellow=$'iso.3.6.1.2.1.43.11.1.1.8.1.3 = INTEGER: 1800'
maxblack=$'iso.3.6.1.2.1.43.11.1.1.8.1.4 = INTEGER: 2500'
cyanperc=$(( ${currentcyan##* }*100/${maxcyan##* } ))
magentaperc=$(( ${currentmagenta##* }*100/${maxmagenta##* } ))
yellowperc=$(( ${currentyellow##* }*100/${maxyellow##* } ))
blackperc=$(( ${currentblack##* }*100/${maxblack##* } ))
echo $cyanperc
echo $magentaperc
echo $yellowperc
echo $blackperc

Instead of echoing the values I want to insert them into a MySql database on a server. Maybe curl?

Any help appreciated.

Raspberry Pi 3 running Ubuntu Mate, GNU, version 4.3.46(1)
# 2  
Old 12-01-2016
If you write them to a delimited file, you can use the mysql tools to load it to a table. You can set the delimiter to anything that you won't otherwise find in the data. Common choices are pipe/vertical bar |, comma , or the at sign @ however the default for MySQL load files is a tab character.

If you get the data in the correct columns and tab separated, then have a look at the syntax page to see how to load it. It can be a bit confusing, but you haven't told us anything about your database to know where you want to load it.

Have a go and if/when you get stuck, show us what you have tried and I'm sure someone will be able to help out. Please describe the target table too and let us know the database name you are connecting to, if it is the default local instance etc.



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting values to database

hi , I'm new to Unix shell scripting. I need help to insert read csv which has two columns -emp no and logged date. csv file is a large file so i want to keep the insertion query in a separate .sql file. csv file looks this: empno | loggeddate ___________________ 5666 ,... (5 Replies)
Discussion started by: preema
5 Replies

2. Shell Programming and Scripting

Inserting values into database from an excel

Hi, I have a requirement where I have an excel sheet with the below values COL1 COL2 COL3 Germany URGENT NORMAL I want to cut the values of this excel in such a way that I get the values and pass it to an insert statement update tbfin set... (2 Replies)
Discussion started by: venkidhadha
2 Replies

3. UNIX for Dummies Questions & Answers

Inserting a variable in awk script

I have file input.txt: >TX1-1 Freq 55 cattctgatgaatatttgtcctttagttgttatttgt >TX1-2 Freq 19 cattctgatgaatatttgtcctttagttgttatttgt >TX1-3 Freq 17 cattctgatgaatatttgtcctttagttgttatttgt >TX1-4 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt >TX1-5 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt ... (5 Replies)
Discussion started by: Xterra
5 Replies

4. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

5. Shell Programming and Scripting

Need help on inserting data from text file to excel using shell script

Hi, Please help me on this. I want to insert data from text file to excel using shell script nawk -v r=4 -v c=4 -v val=$a -F, 'BEGIN{OFS=","}; NR != r; NR == r {$c = val; print}' "file.csv" I used above one to insert $a value in 4th row, 4th column in an excel file.csv and it... (3 Replies)
Discussion started by: suman.frnz
3 Replies

6. Shell Programming and Scripting

Help is Script inserting in db2 tables

Hi, I am creating a shell script to insert few records in db2 tables. I am facing 2 challenges and would appreciate your help on this. 1) In my insert statement like follows: db2 "connect to dbname user user_name"; db2 "insert into table_name (name, phone, ssn) values... (1 Reply)
Discussion started by: pinnacle
1 Replies

7. Shell Programming and Scripting

Script for Logfile Inserting into the Database

Here's the problem. I have a shell script running for every one minute as cronjob that outputs to a log file. I want to be able to take the data from the log file and insert it into a mysql database. The script needs to run at a set period of time and remove the log file data once the insert is... (7 Replies)
Discussion started by: kgrvamsi
7 Replies

8. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

9. Shell Programming and Scripting

Need shell script for inserting New line

Hi All, We have standard programming that creates large files. This file is very big. It contains header record,details records and Trailer record. Details record are of 1024 bytes(Each detail record contains summary(512 bytes) and detail(512 bytes) record). My user wants to insert new line... (16 Replies)
Discussion started by: shivakumar1231
16 Replies

10. UNIX for Advanced & Expert Users

Inserting variables from 2 files to create 1 file

Hi, I have 2 files which are as follows: Num: 548983 748932 783928 547383 839284 Grp: 2389 9873 8493 7382 8493 I need to make an output file using both of these files. (1 Reply)
Discussion started by: rochitsharma
1 Replies
Login or Register to Ask a Question