Performance transaction script

Hi Team,

Any body have script please share me this is important my project.
My team was created one script below as mentioned what we are excepted that out put not generated. at least could you guide below script are we modify anything ?

MONGO_HOME=/hom/bin

$MONGO_HOME/mongo --host mongodb:27017 -u ‘hari’ -p ‘xxxx’
–authenticationDatabase admin --quiet < perf.js > perf.txt
if [ $? -eq 0 ]
then
mailx -s “QUERY TAKING MORE THAN 1 SECOND” hari@xxx.com < perf.txt
else
echo “Unable to connect to MongoDB” | mail -s “Issue while connecting to ADB DB” hari@xxx.com
fi

======================================================================================================

$ cat perf.js
var result=db.currentOp({“active” : true,“secs_running” : { “$gt” : 1 }})
printjson(result)

My management excepted conditions like this :

  1. at any query executed more than 1 second send to mail or do not send mail
  2. once primary not available then which secondary become as primary from primary server executed same script

How to setup that script and deploy ?