MSQL insert record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting MSQL insert record
# 1  
Old 06-25-2011
MSQL insert record

Hi All,

I have created a script to capture process run by the user & put into to mysql DB.

But some how i am anot able to insert output of ps aux as below sting in mysql db.

######################################
Code:
/_TOOLS_/dist/cadence-soc-/81-b014_1-eng/i686-pc-linux2.4/tools/fe/bin/32bit/encounter

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

Using the below commands in my script to do it.
Code:
 id=`ps auxf |grep -w $i|tr -s " "|cut -d " " -f1|sort -nr -k5|grep -v root|grep -v grep`
cmnd="`ps auxf |grep -w $i|tr -s " "|cut -d " " -f11|sort -nr -k5

mysql -u $user -p$pass --database="cdetools" -h "$sqlserver" -e 'insert into cdeprocess (userid,hostname,toolname,cmnd) values ("'$id'","'$host'","'$inputline'","$cmnd")'

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

Kindly let me know how can i do it.

Best Regards

Ankit

Last edited by pludi; 06-27-2011 at 07:07 AM..
# 2  
Old 06-26-2011
Not sure, but it looks like you're missing one set of single quotes around cmnd:
Code:
... values ("'$id'","'$host'","'$inputline'","'$cmnd'")'

BTW, I find that ps aux often doesn't show enough of the command so I use ps auxw.

Also BTW, instead of "|grep -v root|grep -v grep", you can use "|grep -v '[r]oot'".
# 3  
Old 06-27-2011
Quote:
Originally Posted by ajaincv
id=`ps auxf |grep -w $i|tr -s " "|cut -d " " -f1|sort -nr -k5|grep -v root|grep -v grep`
cmnd="`ps auxf |grep -w $i|tr -s " "|cut -d " " -f11|sort -nr -k5`

mysql -u $user -p$pass --database="cdetools" -h "$sqlserver" -e 'insert into cdeprocess (userid,hostname,toolname,cmnd) values ("'$id'","'$host'","'$inputline'","$cmnd")'
##########################################
1.Remove double quote from the variable cmnd and add a closing back quote as highlighted above
2.Im not sure of the use of sort -nr -k5 as you are only chopping of only one column (-f1 and f11) hence sort -nr is adequate.
3.If not sure post, the sample output of your ps aux folks, here would help you out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

2. Shell Programming and Scripting

Insert field values in a record using awk command

Hi Friends, Below is my input file with "|" (pipe) as filed delimiter: My Input File: HDR|F1|F2||||F6|F7 I want to inser values in the record for field 4 and field 5. Expected output HDR|F1|F2||F4|F5|F6|F7 I am able to append the string to the end of the record, but not in between the... (3 Replies)
Discussion started by: Ajay Venkatesan
3 Replies

3. Programming

MYSQL - trigger update on record insert or update

Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works: UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` ); So now I want this... (5 Replies)
Discussion started by: barrydocks
5 Replies

4. Shell Programming and Scripting

Insert a header record (tab delimited) in multiple files

Hi Forum. I'm struggling to find a solution for the following issue. I have multiple files a1.txt, a2.txt, a3.txt, etc. and I would like to insert a tab-delimited header record at the beginning of each of the files. This is my code so far but it's not working as expected. for i in... (2 Replies)
Discussion started by: pchang
2 Replies

5. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

6. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

7. Shell Programming and Scripting

How to insert a single quote to each record

I have a file as: 1 New used 1 used New I need o/p as: '1' 'New' 'used' '1' 'used' 'New' (12 Replies)
Discussion started by: karumudi7
12 Replies

8. UNIX for Advanced & Expert Users

command to insert a record at a particular loaction

Hi, Is there any command to insert a line in between two lines? My input data is as below: 1|ETG|63121387883|Alternate|Y 3|79.58|||GBP|| 4|001137001 4|0011372 5|1021701 5|1021901 1|ETG|63121387884|Alternate|Y 3|79.58|||GBP|| 4|001137001 5|1021702 5|1021802... (1 Reply)
Discussion started by: laxmi131
1 Replies

9. UNIX for Advanced & Expert Users

Compile error for PHP with msql

Hi Folks, I am trying to phpize miniSQL with PHP 5.2.4 on Solaris (SPARC) using GCC 3.4.6. - Unpacked the PHP source to /softwareArchive/php-5.2.4. - Navigated to /softwareArchive/php-5.2.4/ext/msql. - Ran #phpize, then #./configure --with-msql, which worked fine. However when I make, i... (1 Reply)
Discussion started by: brizrobbo
1 Replies

10. Shell Programming and Scripting

How to insert a record in fixed width flatfile

I have a fixed width flatfile with 5 columns, i will load file from oracle database to the flatfile for every 15 min at the end of the file, i want to insert a record by calling a shell script for inserting a record. please can any one help me. Thanks. (1 Reply)
Discussion started by: limou
1 Replies
Login or Register to Ask a Question