2

I have the following shell script, that kicks off a js script against mongo db I wish to pass a variable to the js file. A second caveat is that I need to store this variable somewhere on the unix box to as the last run time of the script. Any help or pointers is appreciated.

# check if previous job still running
if [ -f /tmp/mapreduce_compound.lck ]
then
    exit
else
   # if no lock file present, create one
   touch /tmp/mapreduce_compound.lck
fi

mongo -u xxx mongo1.pilot.dice.com:27017/tracking /usr/local/gemini/mongodb/tracking/mapReduceFunctionsByGroupIdIterative.js > /tmp/mapReduceFunctionsByGroupIdIterative.txt 2>&1


#remove lock file
rm /tmp/process_nightly.lck
1

2 Answers 2

1

To pass additional variables to the javascript file use process.argv. Here is the link to node js documentation.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use

--eval 'var param="$yourparam";'

to pass in arguments.

Note: this isn't passing in arguments so much defining variables your script can use but it does the trick.

So if you wanted to pass the first argument for your shell script in you could do something like this:

# check if previous job still running
if [ -f /tmp/mapreduce_compound.lck ]
then
    exit
else
   # if no lock file present, create one
   touch /tmp/mapreduce_compound.lck
fi

MONGOARG=$1
echo $MONGOARG > lastargcalled

mongo -u xxx --eval 'var param="$MONGOARG";' mongo1.pilot.dice.com:27017/tracking /usr/local/gemini/mongodb/tracking/mapReduceFunctionsByGroupIdIterative.js > /tmp/mapReduceFunctionsByGroupIdIterative.txt 2>&1


#remove lock file
rm /tmp/process_nightly.lck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.