LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2012, 01:20 AM   #1
tedtucker
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Rep: Reputation: Disabled
Query then write to file


I have a dynamic address the I need read into a file every minute. I was looking to write something simple to do this.

When I query this address:
http://abc.com/get_url.php it returns:

__devices__url="http://123.123.123.123/index.php?123abc"
__devices__status__code=0
__devices__error="0"


This then needs to get into url.txt like:

http://123.123.123.123/index.php

Would this be a job for php then call it via cron?
 
Old 04-20-2012, 07:34 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You could do it with a simple shell script. You don't say what command you're using for the "query" so I'll just use "query" in my example - you'd substitute the real command:

Code:
#!/bin/bash
query http://abc.com/get_url.php |grep http |awk -F= '{print $2}'|awk -F? '{print $1}' >url.txt
The above assumes your query output only has one line with http and that it is formatted the way you show.

Of course you could do it with php, perl or any other scripting language you know how to write.
 
1 members found this post helpful.
Old 04-20-2012, 09:00 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
instead of grep, awk, awk, use only one awk:
Code:
query http://abc.com/get_url.php | awk -F\" ' /http/ { print $2 } ' > url.txt

Last edited by pan64; 04-20-2012 at 09:01 AM. Reason: mistyped
 
1 members found this post helpful.
Old 04-20-2012, 12:45 PM   #4
tedtucker
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Unfortantly that is where I get hung up... the responce includes this:

__devices__url="http://123.123.123.123/index.php?123abc"
__devices__status__code=0
__devices__error="0"

AND I just need:

http://123.123.123.123/index.php?123abc

Would wget or php or lynx be an appopriate way to call it?

Thanks for taking your free time to help with my problems! Simply amazing people. I will make sure to pay it forward!

-Ted
 
Old 04-20-2012, 01:49 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You just repeated your original question which is of no help.

What, if anything, did you TRY based on the replies we already made?

When you reply don't just say "I tried it and it didn't work". Tell us the EXACT syntax you typed and the EXACT response it gave you.

You still haven't even told us what you're doing to "query" that is giving you the response. How could we tell you what would be better? EXACTLY what are you typing that is giving the response - don't just say you're doing a query.
 
Old 04-20-2012, 01:56 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite help:
Code:
[schneidz@hyper ~]$ cat ./xbmc/bin/onion.ksh
#!/bin/bash

cd ~/win/stuff/clips/onion
wget http://www.theonion.com/feeds/onn/

i=1
for mp4 in `grep enclosure index.html | awk -F "http" '{print $3}' | awk -F "mp4" '{print "http" $1 "mp4" }'`
do
 last=`basename $mp4`
 if [ "`ls *$last`" ]
 then
  mv *$last `zero-pad-2.x $i`-$last 
  else
   wget $mp4
   mv $last `zero-pad-2.x $i`-$last
 fi
 i=`expr $i + 1`
done

rm index.html
 
Old 04-20-2012, 02:43 PM   #7
tedtucker
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
dear god, it worked.

GET 'http://abc.com/get_url.php?u=user&p=pass' | awk -F\" ' /http/ { print $2 } ' > url.txt

Thanks everybody!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create the file, write into that file but can't delete file in Linux pandunr Linux - Newbie 3 06-15-2011 08:45 AM
[SOLVED] sqlplus query results with spool file go to display and file steven.c.banks Linux - General 2 06-06-2011 03:13 PM
grip : no write access to write encoded file bidouilleur Linux - Software 5 10-09-2010 09:23 PM
Query about NTFS write susovan_pal General 2 06-23-2005 09:39 AM
write an update query in shell prompt to update the database in sqlserver suchi_s Programming 2 09-29-2004 07:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration