How do I fix my shell script for this curl command - json

Hey guys I'm running a shell script through a few loops to acquire records but the curl command is giving me an invalid json error, what am I doing wrong?
resp=$(curl -g -u "${usr}":"${pwd}" -X GET "${env}"/"${name}"/res/"${type}"?where={%22timestamp%22:{%22$gt%22:{%22$date%22:%22"${date1}"%22},%22$lt%22:{%22$date%22:%22"${date2}"%22}}}&paging=limit:100,page:${i})

Quoting hell. printf can help:
url=$(printf '%s/%s/res/%s?where={%%22timestamp%%22:{%%22$gt%%22:{%%22$date%%22:%%22%s%%22},%%22$lt%%22:{%%22$date%%22:%%22%s%%22}}}&paging=limit:100,page:%s' "$env" "$name" "$type" "$date1" "$date2" "$i")
resp=$(curl -g -u "$usr:$pwd" -X GET "$url")

Related

qsub pbs doesn't show error and output log, even forcing the path

when I run code using qsub and pbs script, the log and error files are not shown.
I have also tried to add the path of error and log file, but without succes
#PBS -N example_job
#PBS -j oe
#PBS -q shortp
#PBS -V
##PBS -v BATCH_NUM_PROC_TOT=16
#PBS -l nodes=1:ppn=4
#PBS -e $HOME/error.txt
#PBS -o $HOME/otput.txt
Do you know how can I solve the problem ?
Thanks a lot

Switch user on Google Compute Engine Startup Script

I pass the following as my GCE startup script but it always logs in as the root user and never as the demo-user. How do I fix it?
let startupScript = `#!/bin/bash
su demo-user
WHO_AM_I=$(whoami)
echo WHO_AM_I: $WHO_AM_I &>> debug.txt
cd..`
I think it should work like that:
#! /bin/bash
sudo -u demo-user bash -c 'WHO_AM_I=$(whoami);
echo WHO_AM_I; $WHO_AM_I &>> debug.txt;'
use "sudo-u" to specify the user, then bash -c 'with all the commands between these particular quotes '' and separated by ;
For example: bash -c 'command1; command2;'
You can try an easier test (it worked for me), for example:
#! /bin/bash
sudo -u demo-user bash -c 'touch test.txt'
And then check with ls -l /home/demo-test/text.txt that demo-test is the owner of the new file.

Can't execute some of the curl commands in the quickstart guide

I am working through the Digital Asset quickstart guide.
I am able to run:
curl -X GET http://localhost:8080/iou
And:
curl -X GET http://localhost:8080/iou/0
Without a problem. However, I am having trouble running:
curl -X PUT -d '{"issuer":"Alice","owner":"Alice","currency":"AliceCoin","amount":1.0,"observers":[]}' http://localhost:8080/iou
And:
curl -X POST -d '{ "newOwner":"Bob" }' http://localhost:8080/iou/ID/transfer
I get an output of
<html><body><h2>500 Internal Server Error</h2></body></html>
Is there a log somewhere that allows me to see what error occured? How can I debug this issue?
First I stopped the mvn, navigator and sandbox processes. Then I re-ran
da run damlc -- package daml/Main.daml target/daml/iou
Then I restarted sandbox. and re-entered
mvn clean compile exec:java
Now it works fine...

Bash script output JSON variable to file

I am using twurl in Ubuntu's command line to connect to the Twitter Streaming API, and parse the resulting JSON with this processor. I have the following command, which returns the text of tweets sent from London:
twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text'
This works great, but I'm struggling to output the result to a file called london.txt. I have tried the following, but still no luck:
twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' > london.txt
As I'm fairly new to Bash scripting, I'm sure I've misunderstood the proper use of '>' and '>>', so if anyone could point me in the right direction that'd be awesome!
twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' > london.txt
It will replace on each new line pasting on it. But if you use >> it will append the next write operation to end of file. So try the following rather above example, I'm certain it will work.
twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' >> london.txt
Also you can use tee command to check what is printing along side the redirection
twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text'| tee london.txt

how to run unix command with tcl/expect

I'm new to tcl. I'm trying to run some commands with tcl script.
I searched online and came to know that we can run unix commands with tcl using exec
I executed the following;
perl -i -p -e 's/hello linux./hello fedora. /g;' sample1.txt
from the commandline and it worked. it replaced all the occurences of hello linux with hello fedora.
I tried executing the same command in my tcl script.
set result [exec perl -i -p -e 's/hello linux./hello fedora. /g;' sample.txt]
I got the below error :
child process exited abnormally
I also tried using sed command. I got the same error. I guess there is something wrong with the syntax. I searched online but i couldn't figure it out on my own.
' is not a grouping character in tcl. The equivalent grouping in tcl is {}. Therefore the correct statement is:
exec perl -i -p -e {s/hello linux./hello fedora. /g;} sample.txt
Or even:
exec perl -i -p -e "s/hello linux./hello fedora. /g;" sample.txt