Want to use function and execute the below query in script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to use function and execute the below query in script.
# 1  
Old 02-08-2014
Want to use function and execute the below query in script.

Code:
#!/bin/bash
function getDeliveredDispatches(firstDateTime, lastDateTime, limit) {
var cursor = db.dispatches.find(
{$and: [
{"createdDtm" : {$gte : firstDateTime, $lte:lastDateTime}},
{"status.code" : {$in : ["DELIVERY_PENDING", "DELIVERY_SUCCESSFUL"]}}
]},
{"deliveryGroupId" : 1, "batchId": 1, "statusHistory.code" : 1}
);
var wrongDispatchesIds = [];
print("Number of dispatches selected based on filter = " + cursor.size())
while (cursor.hasNext()) {
var dispatch = cursor.next();
var index_generation_successfull = dispatch.statusHistory.map(function (status) {return status.code}).indexOf("GENERATION_SUCCESSFUL");
var index_delivery_pending = dispatch.statusHistory.map(function (status) {return status.code}).indexOf("DELIVERY_PENDING");

I have the below query which fetches some data from db. Whenever I am trying to execute it in bash I get: syntax error near unexpected token `firstDateTime,'

Kindly assist where am I going wrong. It would be a great help.
# 2  
Old 02-08-2014
Welcome to Forums

This might help you

Bash function syntax

Code:
function function_name {
   your commands goes here...
}

Code:
function_name () {
   your commands goes here...
}

To call function

function_name $argument1 $argument2

Example :

Code:
$ cat tester
#!/bin/bash
foo() {
    echo "First Argument is $1"
    echo "Second Argument is $2"
}

foo argument_1 argument_2 

Code:
$ bash tester
First Argument is argument_1
Second Argument is argument_2

# 3  
Old 02-08-2014
Also, read up on bash syntax first, since there is virtually no discernible bash code in your snippet!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to execute sql query.

Hi Experts, Need your support. Not able to use sql query alias in shell script. Could you please help me in finding right way to use alias with sql query in shell script. Below is the code i am using. #!/bin/bash sqlplus -s abc/abc@abc << EOF> bcd.csv set trimspool on select zone_id... (4 Replies)
Discussion started by: as7951
4 Replies

2. Shell Programming and Scripting

Execute function as soon as input is provided in menu drive shell script

Hi All, I have a menu driven scripts. As you know while running the script we have to input the option such as 1,2, and 3 to execute function accordingly. but after selecting the input we have to press Enter. My requirement is to execute function as soon as we press the option. Is there... (5 Replies)
Discussion started by: kiran_j
5 Replies

3. Shell Programming and Scripting

Call and execute query from tables

Hi.. We have a table DB_QUERIES, in which sql queries are stored. SQL> desc DB_QUERIES Name Null? Type ----------------------------------------- -------- ---------------------------- QUERY_ID NOT NULL NUMBER(10) ... (2 Replies)
Discussion started by: sameermohite
2 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. Linux

PHP is not execute the query from mysql in Linux

Hi , I have ran the php script from Linux box. It is running, But I can able to see any html content. There is no mysql data on that page. I have checked . 1) Mysql and data bases are connected successfully. Please help and guild me If I missed any think during the configuration. ... (13 Replies)
Discussion started by: Mani_apr08
13 Replies

6. Shell Programming and Scripting

Different way to connect to database ans execute sql query

Hi Friends, I am using AIX version and sqlplus to connect to database while writing a shell script. I have implemented three ways to connect to database : 1) sqlplus -s <USERNAME>/<PASSWORD> <<! @<SQL FILE TO EXECUTE> exit ! 2) sqlplus -s <USERNAME>/<PASSWORD> <<! -----sql statemenets... (6 Replies)
Discussion started by: gauravgarg
6 Replies

7. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

8. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

9. Shell Programming and Scripting

TO execute .sql 2005 query file in shell script

Hi, I know in oracle a .sql file is called by @ <path> /<filename>. But how to call in sql 2005, I am opening the sql sessionwith sqsh, is there any command to execute there a .sql file (query in sql 2005) in K shell script. (0 Replies)
Discussion started by: n2ekhil
0 Replies

10. Shell Programming and Scripting

Execute oracle query determined at runtime from a unix script

Hi I am trying to run a SQL statement from a unix script determined at runtime. It is throwing me an error. Please advise some solution to this. echo "Enter username for the database" read username echo "Enter password for the database" read password echo "Enter SQL stmt" read... (4 Replies)
Discussion started by: infyanurag
4 Replies
Login or Register to Ask a Question