LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 06-09-2009, 04:15 PM   #1
redss
Member
 
Registered: Jun 2003
Posts: 147

Rep: Reputation: 16
How to execute binary executable using wget


I can locally execute a shell script that resides on a webserver by piping the script to sh, with the following command:
Code:
wget www.somewhere.com/somefile.sh -O - | sh
Now how can I execute a BINARY executable that resides on a webserver?
 
Old 06-10-2009, 01:21 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 595

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by redss View Post
I can locally execute a shell script that resides on a webserver by piping the script to sh, with the following command:
Code:
wget www.somewhere.com/somefile.sh -O - | sh
Now how can I execute a BINARY executable that resides on a webserver?
What wrong with
Code:
wget www.somewhere.com/somefile.exe
chnod 755 somefile.exe
./somefile.exe
 
Old 06-10-2009, 12:16 PM   #3
redss
Member
 
Registered: Jun 2003
Posts: 147

Original Poster
Rep: Reputation: 16
That would work, but it's 3 lines as opposed to one line. And the same filename has to be redundantly used 3 times. If there's a way to do it with one command, I want to do it that way, it would look cleaner :-)
 
Old 06-11-2009, 01:27 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 595

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by redss View Post
That would work, but it's 3 lines as opposed to one line. And the same filename has to be redundantly used 3 times. If there's a way to do it with one command, I want to do it that way, it would look cleaner :-)
Put it in the script.
Code:
#!/bin/sh
[ $# -ne 1 -o "x$1" = "x" ] && {
   echo "Usage: $0 <url>" 1>&2
   exit 1
}
url=$1
filename=`basename $url`
wget $url
chmod 755 $filename
./$filename
 
Old 06-11-2009, 02:49 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,905

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
There's a primordial difference. Bash are not executable files per se, they are interpreted by bash, in a similar sense that odt files are interpreted by your word processor. So you can read bytes and pipe them into bash (or any other program, as long as it can use a pipe for input).

Binary files are interpreted by your kernel directly, as long as they are a.out or elf files. So you would need to pipe the binary into the kernel elf loader. If could be theoretically possible to read the bytes from the web and send them directly to a device node that would consume them into the loader. This would illustrate the idea (but it's just an sci-fi example, don't dare to try it):

Code:
wget -O - -q http://wahtever | cat > /dev/elf_loader
# or less graphically, but the same
wget -O - -q http://whatever > /dev/elf_loader
However I have no idea how could that be done, if at all. With a bit of kernel hacking it should be possible, I guess

Last edited by i92guboj; 06-11-2009 at 02:54 AM.
 
Old 06-11-2009, 11:37 AM   #6
redss
Member
 
Registered: Jun 2003
Posts: 147

Original Poster
Rep: Reputation: 16
Ok, so there's no simple way to do it, other than writing a script to do that. Thanks all!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't execute an executable, even as sudo. davemar Suse/Novell 2 06-25-2008 06:59 AM
php executable binary apt Programming 4 12-08-2004 08:46 AM
Wget - forcing binary mode? Darklegion Linux - Software 1 08-25-2004 11:24 PM
Why the executable file could not execute? jeson_515 Programming 3 03-14-2004 09:40 PM
Cannot execute executable files without ./ brady9953 Linux - Newbie 3 10-13-2003 03:19 PM


All times are GMT -5. The time now is 03:40 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration