Author Topic: command output to command input?  (Read 820 times)

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« on: 23 August 2002, 12:07 »
Anyone know how I can get the output of one command to go to the input of another. For instance:
echo y | format /U c:
(not for that purpose though)
I want to be able to make a script that can send the output of an echo script to an ssh command so that I can connect to my server and execute commands as a different user. so in the format above:
./passandcmd | ssh [email protected]
would send the ouput of passandcmd to the input of ssh. Any suggestions?

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command output to command input?
« Reply #1 on: 23 August 2002, 12:18 »
you want passandcmd to be an argument or what ssh will send to the remote computer after connected?
I'm assuming passandcmd is short for password and command so you want it to input the password then the command after it connects.
Wouldnt that mean the password would be in plain text???
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #2 on: 23 August 2002, 12:22 »
it wouldn't send the password over a connection, just to that program, which then encryptes it and sends it over the web to the server. that was just an example though. perhaps a bad one. how about this:
ls | sort
so that it will sort the output of the ls command. I just want to know the format of sending the output of one command to the input of another. ls > ./savefile will save the output, but not do anything with it, what would i have to send it to a command instead of a file?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command output to command input?
« Reply #3 on: 23 August 2002, 13:02 »
Are client and server both UNIX/Linux?  If so this is really easy although there are even easier ways using SSH than what you are describing. Can you give a detailed description of what you want to accomplish? And you can set up SSH so it does not require a password using "ssh-keygen" (man ssh-keygen), and the userIDs do not have to match.
Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #4 on: 23 August 2002, 13:21 »
All I want to accomplish is the knowledge of how to send the output of command A to the input of command B. I dont have any specific goal in mind anymore, I just want to learn something new. And this is 1 thing I know how to do in windows but not linux. I'm not so sure how I could get really detailed about it. lets say I make a program that records all the input it gets, and once it stops recieving input for more than 2 seconds it closes. how would I send 'ls' to that program?

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command output to command input?
« Reply #5 on: 23 August 2002, 13:25 »
wouldnt it just be something like
rpm -qa | grep pimp
that would search the rpm database and find RPMS with the word pimp in them.

or somthin like
cat /var/run/windows.pid | xargs kill -9
which would read the file named /var/run/windows and then kill whatever cat outputs (which would be the pid)

[ August 23, 2002: Message edited by: Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command output to command input?
« Reply #6 on: 23 August 2002, 13:26 »
$ ls -alp | ssh username@host "cat > /tmp/ls.txt"

would list the directory contents of the current directory on the local client and pipe the output to the "cat" command on the remote server and redirect it to /tmp/ls.txt on the remote server...
Someone please remove this account. Thanks...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command output to command input?
« Reply #7 on: 23 August 2002, 13:29 »
Oh yeah, try *that* in Windows unixluser.  

[ August 23, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #8 on: 23 August 2002, 13:30 »
Alright, this helps a lot. thanks. So it is the same, I was just having problems with ssh as I couldn't send anything to the password prompt. All goes well now.

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #9 on: 23 August 2002, 13:35 »
Is it possible to do:
echo apassword | su
(despite it's incredible insecurity, is it possible?)

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command output to command input?
« Reply #10 on: 23 August 2002, 13:35 »
The way I have my stuff set up it doesn't ask me for a password as I am using ssh keys and identity files.
Someone please remove this account. Thanks...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command output to command input?
« Reply #11 on: 23 August 2002, 13:37 »
quote:
Originally posted by Stryker:
Is it possible to do:
echo apassword | su
(despite it's incredible insecurity, is it possible?)



No. You can set up "sudo" if you need to allow certain commands to run as root from a normal user account.
Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #12 on: 23 August 2002, 13:39 »
Alright, i'll look up docs on that, and voidman, you abondoned my post for the laptop.  :confused:  still dont know what to do about the dvd.

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
command output to command input?
« Reply #13 on: 23 August 2002, 13:46 »
All I want to accomplish is the knowledge of how to send the output of command A to the input of command B. I dont have any specific goal in mind anymore, I just want to learn something new. And this is 1 thing I know how to do in windows but not linux. I'm not so sure how I could get really detailed about it. lets say I make a program that records all the input it gets, and once it stops recieving input for more than 2 seconds it closes. how would I send 'ls' to that program?

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command output to command input?
« Reply #14 on: 23 August 2002, 13:53 »
program in what C++?
you can make a system call for ls, which is the same as typing ls at the prompt:
Code: [Select]

(i deleted your double post)

[ August 23, 2002: Message edited by: Master of Reality / Bob ]

[ August 23, 2002: Message edited by: Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'