LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-28-2009, 09:35 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
What is the best way to get a variable from another server with a shell script?


What is the best way to get a variable from another server with a shell script?

IE. Can I have domain.com/var.txt
and var.txt contains either a 0 or a 1
and then have a shell script run every 5 minutes via crontab with the code as follows (so if var.txt contains a 1, dostuff.sh will execute):
#!/bin/bash
var = wget domain.com/var.txt
if $var == 1
/root/dostuff.sh

TIA!
 
Old 01-29-2009, 02:31 AM   #2
secondmouse
LQ Newbie
 
Registered: Sep 2008
Location: NYC
Distribution: Gentoo, Ubuntu, SuSE
Posts: 3

Rep: Reputation: 0
There are number of ways, using wget with option -O (as in OK) like this should be the easiest:
Code:
var=$(wget -O - http://domain.com/var.txt)
the O option is to output result to stdout instead of a file.
[ More wget examples can be found @ http://www.editcorp.com/Personal/Lar...v1/wget_7.html ]

Or you can use a python script like this to do the job:
Code:
#!/usr/bin/env python
import os
from urllib import urlopen
raw_text=urlopen('http://domain.com/var.txt').read()
var=raw_text.strip()  # in case there's ending \n
if var=='1':
    f=os.popen('/root/dostuff.sh')
    # the stdout can then be obtained through f.readline(), if needed
 
Old 01-29-2009, 03:34 PM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Thanks!

I actually ended up doing it in perl:
#!/usr/bin/perl
$var=qx[wget -O - http://domain/var.txt];
if($var > 0){
qx[sh /root/dostuff.sh];
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Shell Script and Dynamic variable xanthium Programming 11 07-12-2011 06:05 AM
Shell Script Random Variable Daniel Programming 14 12-03-2007 05:00 AM
shell script: redirect to variable va1damar Programming 1 02-05-2007 04:11 PM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 04:56 PM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 05:05 PM

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

All times are GMT -5. The time now is 10:16 AM.

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