PDA

View Full Version : extract line from a text file



kurtdriver
24th August 2010, 08:54 PM
Hi, I'm pulling my hair out trying to figure this error message out. This little script is supposed to tweet my laptop's IP address, as a cron job, I'm hopeful that it would do so even if it's stolen. This is a variant of one that works, but this doesn't, and I can't see a difference in the curl line of either one.


#!/bin/bash
user="xxxxxx@xxxxxxxxx"
pass="xxxxxxxxxxx"

wget http://www.whatismyip.org/
TWEET=`sed -n 1p index.html`

curl --basic --user "$user:$pass" --data-ascii \"status=$TWEET" "http://twitter.com/statuses/update.json"
rm -f index.html
exit


This is the error message.



curl: (6) Could not resolve host: status=66.183.103.67; Cannot allocate memory
{"request":"/statuses/update.json","error":"Client must provide a 'status' parameter with a value."}

Why does curl think the status is the URL?

recondite
24th August 2010, 11:23 PM
Why not post the one that works too?

---------- Post added at 02:23 PM CDT ---------- Previous post was at 02:12 PM CDT ----------

There are three types of quote characters: single ('), double ("), and backquote (`) and each is treated differently by the shell. Did you change a quote or two?

kurtdriver
25th August 2010, 12:15 AM
Hi and thanks for you reply, I copied this and modified it accordingly.


#!/bin/bash

USER="xxxxxx"
PASS="xxxxxxxx"
TWEET=$@
echo "$TWEET"

curl --basic --user "$USER:$PASS" --data-ascii \ "status=$TWEET" "http://twitter.com/statuses/update.json"

exit


Unrelated note: how do I change a title? This was for another thread, then I remembered that sed would do it.

Edit: I copied and modified again and it works. So not Solved, but Fixed.

recondite
25th August 2010, 04:28 AM
Well, for one thing, there is a difference between $USER and $user.

There is also a difference between \" and \ " (note the space in the second case).

kurtdriver
25th August 2010, 04:37 AM
Well, for one thing, there is a difference between $USER and $user.

Thanks again, but the variables are the same within particular scripts, the two scripts user slightly different ones.


There is also a difference between \" and \ " (note the space in the second case).
Yeah, I tried it each way in the second and just left it without the space in the first when I posted it.
I do appreciate your efforts. Kurt

MAmundson
25th August 2010, 05:28 AM
Would it work if you changed \"status=$TWEET" to \"status=$TWEET\"?

weitjong
25th August 2010, 04:22 PM
I suspect your $TWEET variable has empty value. Have you double checked that by outputting its value by using echo command like in your original version of the script?

kurtdriver
25th August 2010, 10:16 PM
I suspect your $TWEET variable has empty value. Have you double checked that by outputting its value by using echo command like in your original version of the script?

I did, those echos were just tests. In the error message in the original post the value of that variable is right there (66.183.103.67). The error message seems to say that curl mistakes the $TWEET as the url, but the line that reads
{"Client must provide a 'status' parameter with a value."} came from twitter I imagine.