Want to call batch file with node script, get garbled time - node.js

I want to create a cron job with a batch file which is using curl to login into a page saving the login token and then run a node script to do something. But when I call my batch file I get
batch: garbled time
My script:
#!/bin/bash
# A simple script to automate something
curl 'someurl' -H 'content-type: application/json' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Referer: someurl' --data-binary '{"some login data"}' -i -O
node doSomething.js

If you are trying to submit your script as a crontab file, then it's in the wrong format. You need to specify time-related fields at the start of the line. See https://en.wikipedia.org/wiki/Cron
The error message you got is typical of a bad time specification.

Related

windows command prompt curl POST to run Azure DevOps pipeline

I am trying to run an Azure DevOps pipeline from the windows command prompt using curl.
Based on Microsoft documentation ( Runs - Run Pipeline ) I should be able to run a pipeline by posting:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
I am able to GET using the command:
curl -u :<PAT> https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
However, I can't figure out how to do a POST for DevOps using curl to run the pipeline.
I have tried the following:
curl -s -X POST -L https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1 -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic <PAT>"
But this returns the error
HTTP Error 411. The request must be chunked or have a content length
I managed to solve my problem which consisted of numerous steps:
Log the API call from the DevOps website to get the correct format of the json-body ( See this question ).
Format the json-body with extra double quotation signs.
Use the {project}-id instead of the ascii-name since it included a special character which the command prompt misinterpret.
Hence the complete curl command was:
curl -X POST -u :<PAT> "https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1" -H "Content-Type: application/json" -d "{""stagesToSkip"": ""[]"", ""resources"": {""repositories"": {""self"": {""refName"": ""refs/heads/master""}}}}"

Store output of command in variable where the command is already executed/stored in it's own variable - bash script

I have a command that is stored in a variable. I would like to execute that command and then store the response of that command in a variable. I'm having an issue with syntax errors for the responseVar=$("{commandVar}") line as it seems to trigger a "no such file or directory" error instead of actually running the command/storing the output in the response variable.
commandVar="curl --location -g --request POST 'https://172.217.25.35/rest-gateway/rest/api/v1/auth/token' --header 'Content-Type: application/json' --header 'Authorization: Basic U0FNcWE6NTYyMFNhbSE=' --data-raw '{"grant_type": "client_credentials"}'"
responseVar=$("{commandVar}")
echo "Response of command: ${responseVar}"
Does anyone know the correct syntax on how I would do this? I need to eventually parse the output of the command which is why I need to store the response in it's own variable.
You are trying to execute a program named {commandVar}, and this program does not exist in your PATH.
To start with, you better use an array to store your command, each array element holding one command argument:
commandVar=(curl --location -g --request POST 'https://172.217.25.35/rest-gateway/rest/api/v1/auth/token' --header 'Content-Type: application/json' --header 'Authorization: Basic U0FNcWE6NTYyMFNhbSE=' --data-raw '{"grant_type": "client_credentials"}')
With this, you can execute it by
"${commandVar[#]}"
respectively store its standardoutput into a variable like this:
responseVar=$( "${commandVar[#]}" )

how to write curl command for getting data which updated in last 10 min

i have tried these two curl command but not getting correct response
curl --request GET 'https://localhost:8080/api/alarms?sort-by=lastReceiveTime&from-date=date -d'now-10 minutes'' -H 'Authorization: Key demo-key
curl --request GET 'https://localhost:8080/api/alarms?sort-by=lastReceiveTime&from-date="'"$(date --utc +%FT%T.%3NZ) -d 'now-10 minutes'"'"' -H 'Authorization: Key demo-key'
this command gives all alarm ...but we want only those alarm which came in last 10 min.

Using CURL to upload to Dropbox and overwrite a file

I'm a small time admin and would say entry level to Linux. I am trying to use CURL to upload to Dropbox a small backup sqlitedb and have had success for the first upload, however, I am trying to accomplish uploading a file to Dropbox every 30 minutes and overwriting the current file in DROPBOX with the new file from my Linux server (as a jerry-rigged offsite backup of my Teamspeak database)
This is the code I have so far :
curl -X PUT https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <dropbox code here>" \
--header "Dropbox-API-Arg: {\"path\": \"/home/ec2-user/ts3server.sqlitedb.bz2\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary ts3server.sqlitedb.bz2
After running that code once, it doesn't OVERRIDE the current file in my Dropbox account with the updated file. Any help is appreciated
you need to use mode with parameter overwrite. The default is add.
Add - Do not overwrite an existing file if there is a conflict. The autorename strategy is to append a number to the file name. For
example, "document.txt" might become "document (2).txt".
overwrite - Always overwrite the existing file. The autorename strategy is the same as it is for add.
Reference: /upload
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer " \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary #local_file.txt

curl command in linux

How we can add JSON parameters in a curl command to fetch data ?
PS: I have tried to fetch data from some source using curl command but it requires passing JSON parameters in it. So how I will accomplish it ?
I think mentioning content type as json and passing data will do the things right
curl -H "Content-Type: application/json" -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here
Above will work for GET Method, for POST method
curl -H "Content-Type: application/json" -X POST -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here

Resources