curl fail to save into a file even when specifying output - file

Im trying to save curl result into a file so I can analize it later using other tools.
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date
the command works fine and I get the result on screen. The problem arises when I want to save it to a file. I have read related questions in stackoverflow and I think this one is a bit different.
When I use the command:
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date > testing.txt
Nothing is written into the file and the outputs once again goes to the screen.
I tried using the output choice
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date --ouput testing.txt
But curl says that doesnt recognize the command and prints the result to the screen. Same result using "-o".
I used curl in a localhost web server and everything worked ok. I think the difference resides in size because I also used on www.google.com and it worked just fine too. Did anyone run into the same problem before?

Place the options before the URL. Using —output is the best way, as it doesn’t clobber stdout. If this change still “doesn’t recognize the command”, maybe it is a really old or fake curl (like in PowerShell)? I usually run with -vv interactively, as it can sometimes show things like not following redirects (see/use -L to automatically follow) — https://linux.die.net/man/1/curl
So something like the following might be useful, to either fix the issue due to proper URL placement and ensuring to following redirects, or failing that, showing useful diagnostic information:
url=https://www.revolico.com/...
curl -vv -L --output testing.txt $url

Related

Copying/redirecting browser console output to shell

Is there a way, in Linux, to make the electron executable copy or redirect output sent to its console to the shell console, i.e. when I run it from a terminal?
For instance, if I run, in a shell, electron foo.js, where foo.js contains simply console.log("foo"), I get the foo message echoed back to my terminal.
However, when I run a React app, the output of console.log is directed to the browser's console (as explained here).
Is there a way to copy/redirect the outputs sent to the browser Console, so that they will also be sent to the shell console? This can be very useful for some kinds of debugging (e.g. using grep and regexes).
Alternatively, if there are other methods than console.log that allow writing to the shell which created the browser process, that would also be helpful.
Edit: #0stone0 mentioned the difference between server code and client code; from the point of view of debugging, since I am running a local process, the browser could very well decide to copy its console output to stdout/stderr. I fail to see why technically Chromium could not do it; requiring an API or websockets for this use case seems excessive, but if that is indeed necessary (e.g. for security reasons), that is a valid answer for me.
I just found a way, thanks to this question:
Q: Does anyone know of a way to save the console.log output in Chrome to a file? Or how to copy the text out of the console?
A: Enable logging from the command line using the flags:
--enable-logging --v=1
I then combined it with the answer to this question to set the Chromium flag in my Electron app:
app.commandLine.appendSwitch('enable-logging');
And that is enough for me to get messages in my console, such as:
[1234:0328/3923.5981:INFO:CONSOLE(2)] "logging", source: file:///home/user/app/main.js

How to respond to any command line prompts in C

I'm trying to automate the process of doing
git add .
git commit -m "some message"
git push origin master
In C.
I've already done a bash script with Expect
#!/bin/bash
HOME="/home/prxvvy"
filename="$HOME/Documents/github_creds.txt"
username=`awk 'NR==1' $filename`
password=`awk 'NR==3' $filename`
echo "Enter a message for commit:"
read message
expect <<EOS
spawn git add .
expect
spawn git commit -m "$message"
expect
spawn git push origin master
expect "Username for 'https://github.com':"
send "$username\r"
expect "Password for 'https://$username#github.com':"
send "$password\r"
expect eof
EOS
So how would I "send" the requested data when the "Username for 'https://github.com':" prompt comes up, with C?
PS: I don't want to use any git api or something as I did in the bash script
Answer #1: you can't. The problem here has nothing to do with Git per se. Programs that read passwords from humans make sure they're not talking to other programs, by making sure they're using the human /dev/tty interface. So your program can't push a password into another program.
Answer #2: you can, but you must re-implement expect. The expect program tricks other programs into thinking they are talking to a human. This is fairly complicated and involves opening a "pseudo tty" from the control side, initializing it properly on the dependent side, and doing any OS-level operations required to make it become the /dev/tty that other programs will get when they open it. Then, having done all this song and dance (some of which is available in some libraries via openpty or similar), you can then run a program. You then must implement the rest of expect to read data coming through the control side of the pty pair, interpret it to figure out what the program is doing, and feed it data.
(Note that if all you want to do is run git push without having to enter a password, Git can invoke authentication methods that do this. Git does not have its own built in authentication: it relies on credential helpers when using https and ssh's credentialing and authentication systems when using ssh. So if you're using https:// for your URL, you want to configure a credential helper to do the job, and if you're using ssh:// for your URL, you want to configure ssh. You said that's not what you're interested in, though.)

How do I know what parameters nl80211 commands require?

My main reference is http://lxr.free-electrons.com/source/include/uapi/linux/nl80211.h
Let's say I want to call NL80211_CMD_TRIGGER_SCAN documentation says trigger a new scan with the given parameters NL80211_ATTR_TX_NO_CCK_RATE is used to decide whether to send the probe requests at CCK rate or not.
I am looking at some source I found online, but it does not work and I would
So how do I know what to put into message?
I am using libnl to comunicate with kernel
I found some answers online that put a little light on this, but it's still a dark alley to me. Here are some:
Using nl80211.h to scan access points
how to use the libnl library to trigger nl80211 commands?
I ran into the same issues working from a Python perspective. From personal experience, the iw source code sucks. You'd be better off doing
strace -e trace=network -f -x -s 4096 iw ...
I built a simple parser and copying and pasting the output, I was able to figure out what nl80211 command and attributes along with values were being sent and then see what the response was.

<VirtualHost> error in Apache2.conf

I cannot fix this without asking for help. On install of LAMP via Syn. Pkg. Mgr. and trying to setup and run LAMP, I have received:
mark#Lexington:/$ apachectl restart
/usr/sbin/apachectl: 87: ulimit: error setting limit (Operation not permitted)
apache2: Syntax error on line 237 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/example.com: /etc/apache2/sites-enabled/example.com:1: <VirtualHost> was not closed.
The /etc/apache2/apache2.conf file talks about a <VirtualHost> and I have read examples of what to put there, but I'm not able to understand what I am doing. And since the file says DON'T unless you know what you are doing, I am asking:
This is XUbuntu 12.04. I tried installing LAMP. The purpose of this is to run vnstat in a browser and see the bandwidth usage. Also, I want to "serve" a mp3 file to a weblog I keep. I don't understand why I would make an Apache error log visible in a browser. I would have little reason to see the bandwidth usage at another location. The only other reason for LAMP is I am trying to use MythTV to send the TV signal to a "smart" tv via ethernet cable.
If you can point me towards a URL or other help, I'm much obliged.
If you can give me the name of a text editor that shows line numbers so I can look at "line 237" I'll try to figure the syntax error.
oh, this looks easy...i think. You'll see <VirtualHosts> near or at the top of the file /etc/apache2/sites-enabled/example.com (error says line 1). Scroll down through everything. if you do not see </VirtualHosts> (notice the slash), put that in the bottom of the file. Save and close, then restart apache
Regarding the "operation not permitted": you may have to use sudo to elevate your privileges (assuming you are on unix, which i think you are). Research how to do this if you don't know.

Check if file exists on FTPS site using cURL

I am using the cURL app to download multiple csv files. I want to find a way to check if the file exists on the ftps site before kicking off the download. If it doesn't exist I would like to find a way for cURL to check again at regular intervals.
I am trying to stick to using cURL commands for this I am really not good at .Net programming. Any help would be appreciated
$ curl ftp://[host]/[path] --ssl --head
(you might also need -k)
--ssl: Try to use SSL/TLS for the connection
--head: When used on an FTP or FILE file, curl displays the file size and last modification time only
It will return an error if the file doesn't exist. It will not keep checking, it will only check once so you need to do the repeated checking using some scheduler/cron/script or whatever.

Resources