Usage of Wget for a long URL - linux

I am trying to download a file with the below URL:
wget http://example.com/reports/downloadreport?roleId=8&loginName=9011613&code=123
But it takes only till
http://example.com/reports/downloadreport?roleId=8
not sending the remaining things. I need to send at least role ID and loginName to get the file.
I tried to create a shell script like below, but that is not working either:
i="http://euroams.eurekaforbes.co.in:8080/efms/reports/bamsinvoiceresultdownload?roleId=8&loginName=9011613"
wget --tries=45 -i $i
How can I fix this?

Enclose the URL in quotes. Your shell is interpreting the "&" rather than passing it as a parameter, so it's seeing what you typed as the following (three commands rather than one):
wget http://example.com/reports/downloadreport?roleId=8 &
loginName=9011613 &
code=123

Related

Problem running bitbucket rest api command using python

I,am building a script to update files on Bitbucket using the rest api.
My problems are:
Running the command using subprocess lib and running the command directly on the command line gives two different results.
If I run the command using the command line, when I inspect my commits on the Bit bucket app I can see a Commit message and a Issue.
If I run the command using the help of the subprocess lib I don't have a commit message and a Issue in the end. The commit message sets itself by default to "edited by bitbucket" and the issue is null.
This is the command:
curl -X PUT -u user:pass -F content=#conanfile_3_f62hu.py -F 'message= test 4' -F branch=develop -F sourceCommitId={} bitbucket_URL".format(latest_commit)
The other problem is that I need to pass a file to the content in order to update it.
If I pass it like above it works. The problem is that I am generating the file content as raw string and creating a temporary file with that content.
And when I pass the file as a variable, it does not get the content of the file.
My code:
content = b'some content'
current_dir = os.getcwd()
temp_file=tempfile.NamedTemporaryFile(suffix=".py",prefix="conanfile", dir=current_dir)
temp_file.name = temp_file.name.split("\\")
temp_file.name = [x for x in temp_file.name if x.startswith("conanfile")][0]
temp_file.name = "#" + temp_file.name
temp_file.write(content)
temp_file.seek(0)
update_file_url = "curl -X PUT -u user:pass -F content={} -F 'message=test 4' -F branch=develop -F sourceCommitId={} bitbucket_url".format(temp_file.name, latest_commit)
subprocess.run(update_file_url)
Basically I'am passing the file like before, just passing the name to the content, but it does not work.
If I print the command everything looks good, so I don't know why the commit message does not get set and the file content as well.
Updated:
I was able to pass the file, My mistake was that I was not passing it like temp_file.name.
But I could not solve the problem of the message.
What I found is that the message will only take the first word. If there is a space and one more word after, it will ignore it.
The space is causing some problem.
I found the solution, if someone found himself with this problem we need to use a \ before the message= .
Example: '-F message=\" Updated with latest dependencies"'

Use bash variable in substitution command with this formatting, with JSON

I have a bash script where one of the part in a command changes from time to time.
So I tried to change the script, so we could ask for it, or change at one part only, etc., but can't really make it.
If I write this, it works:
#!/bin/bash
changing_stuff='"Active-2021-xy Part YX"'
total_number=`Command_xy show base name "Active-2021-xy-yz Part YX" limit 1 --format json | jq '.total'`
I've used '" "' because as you see in the original command it requires " " for that part.
How could I add the changing_stuff into the middle of the script?
Thanks a lot!
The following should work. There's no need to add quotes into your changing_stuff variable. Putting quotes around the variable when you use it causes the whole value (including the spaces) to be passed as a single argument to Command_xy.
#!/bin/bash
changing_stuff='Active-2021-xy Part YX'
total_number=`Command_xy show base name "$changing_stuff" limit 1 --format json | jq '.total'`
You seem to be looking for the trivial
#!/bin/bash
changing_stuff='Active-2021-xy Part YX'
total_number=`Command_xy show base name "$changing_stuff" limit 1 --format json | jq '.total'`
The quotes are simply a mechanism for keeping the string with spaces in it as a single argument, in both places.
(Tangentially, you also want to replace the backticks with modern command substitution syntax:)
#!/bin/bash
changing_stuff='Active-2021-xy Part YX'
total_number=$(Command_xy show base name "$changing_stuff" limit 1 --format json | jq '.total')

how to pass float value as query params using curl?

I have a python flask server running and the following http GET works on my browser, http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741 , however when I use command curl http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741 it doesn't work. How to correct my query to work for curl?
You have to pass URL as a string.
It's because for shell a lot of characters used in URL have special meaning (ie = is an assignment, & makes command to run in background, etc). So
curl "http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741"
should work as expected.
To pass the query-parameters separated and let cURL build the query-string we can also use option -G together with usual -d like
curl -G -d 'lng=18.565810740668912' -d 'lat=-33.93153605161741' http://example.com/v1/api
See also: Construct a Query String (TLDR: Use -G argument)

Bash String Interpolation wget

I'm trying to download files using wget and for some reason I think I'm encountering some problems with string interpolation. I have a list of files to be downloaded that I have successfully parsed etc (no small feat for me) and would like to incorporate these into a for loop wget statement combo which downloads these files en masse.
Please forgive me the URLs won't work for you because the password and data have been changed.
I have tried single and double quotes as well as escaping a few characters in the URL (the &s and #s which I presume are at the marrow of this).
list of files
files.txt
/results/KIDFROST#LARAZA.com--B627-.txt.gz
/results/KIDFROST#LARAZA.com--B626-part002.csv.gz
/results/KIDFROST#LARAZA.com--B62-part001.csv.gz
wget statement works as a single command
wget -O files/$i "https://tickhistory.com/HttpPull/Download? user=KIDFROST#LARAZA.com&pass=RICOSUAVE&file=/results/KIDFROST#LARAZA.com--N6265-.txt.gz"
but a loop doesn't work
for i in `cat files.txt`; do
wget -O files/$i "https://tickhistory.com/HttpPull/Download? user=KIDFROST#LARAZA.com&pass=RICOSUAVE&file=$i"
done
Edit: Main issues was "files/$i" instead of "files$i" (see comments)
Don't use a for-loop/cat for reading files, use a while/read loop. Less problems with buffer-overflow/splitting/etc...
while read -r i; do
wget -O "files$i" "https://tickhistory.com/HttpPull/Download? user=KIDFROST#LARAZA.com&pass=RICOSUAVE&file=$i"
done < files.txt
Also make sure you quote variables to prevent expansion/splitting errors. Also not really sure why you're doing files/$i, since $i has full path.

I get a scheme missing error with cron

when I use this to download a file from an ftp server:
wget ftp://blah:blah#ftp.haha.com/"$(date +%Y%m%d -d yesterday)-blah.gz" /myFolder/Documents/"$(date +%Y%m%d -d yesterday)-blah.gz"
It says "20131022-blah.gz saved" (it downloads fine), however I get this:
/myFolder/Documents/20131022-blah.gz: Scheme missing (I believe this error prevents it from saving the file in /myFolder/Documents/).
I have no idea why this is not working.
Save the filename in a variable first:
OUT=$(date +%Y%m%d -d yesterday)-blah.gz
and then use -O switch for output file:
wget ftp://blah:blah#ftp.haha.com/"$OUT" -O /myFolder/Documents/"$OUT"
Without the -O, the output file name looks like a second file/URL to fetch, but it's missing http:// or ftp:// or some other scheme to tell wget how to access it. (Thanks #chepner)
If wget takes time to download a big file then minute will change and your download filename will be different from filename being saved.
In my case I had it working with the npm module http-server.
And discovered that I simply had a leading space before http://.
So this was wrong " http://localhost:8080/archive.zip".
Changed to working solution "http://localhost:8080/archive.zip".
In my case I used in cpanel:
wget https://www.blah.com.br/path/to/cron/whatever

Resources