Linux send command to terminal

Thread: Send Command to Terminal

Hovercat is offlineGee! These Aren’t Roasted!

Send Command to Terminal

I have a Minecraft server running through one Terminal, I want to be able that when cron executes a bash script, it sends the command to the terminal «save-all» (which is a Minecraft server command). How can I do this?

Hovercat is offlineGee! These Aren’t Roasted!

Re: Send Command to Terminal

Cheesehead is offlineUbuntu Member

Re: Send Command to Terminal

Bumping more frequently than 24 hours is considered rude in this forum.

Hovercat is offlineGee! These Aren’t Roasted!

Re: Send Command to Terminal

Cheesehead is offlineUbuntu Member

Re: Send Command to Terminal

It’s not that hard. Just play with it a little, send a test command between ttys, and you’ll get the hang of it within 10 minutes.

phil338198 is offlineFirst Cup of Ubuntu

Re: Send Command to Terminal

Hi! I’m in exactly the same situation.
I’ve read and tried everything I could find about doing something like this:
ls -l > /dev/pts/1
and it all works as described.
The thing is, this displays the output of the command in the terminal pts/1. What I need is for the command to be executed by pts/1.

Example:
In pts/1 I have python running in interactive mode. It shows

then pts/2 tells me that there is an error with the command (which is normal since it’s a wrong syntax for a bash command)
If I type

echo "exit()" and echo -ne "exit()/n"

to send a line return, but it does not work. Also, if I go to pts/1 to press RETURN after I sent exit(), it acts as if exit() was never there.

Читайте также:  Linux посмотреть подключения tcp

It seems like the method I tried will only send things to the display of another terminal. I would like to send things to the input of a terminal to make it execute it. In the minecraft case, I need the server (which has an interactive command prompt) to execute the command «save-all», which does not works using
save-all > /dev/pts/1

I hope I have been clear enough for someone to be able to help us both!

Источник

How can I pipe commands to any terminal?

I often use more than one terminal (or terminal emulator) at a time; and while in X I can copy-paste commands, besides not being very practical, it obviously does not work on the real TTY. The first idea that occurs to me is something alike:

Unfortunately, the command is run before it is piped, and no tricks like echo `command` will work, no matter how many weird bash characters ( $ , ` , » , etc.) are there. So /dev/sometty simply gets some text. The problem is that, sometimes, it is even worth for I to pipe those commands into a file, make it executable, etc., or shortly: making a script and running it from the appropriate terminal. But that is a lot of work. I’ve been thinking of making a script to make these files, for an instruction:

termpipe -e "command1\ncommand2\"command 1 argument\\n(s)\"" -t /dev/sometty 
  1. pipe the commands to, say, /tmp/termpipe-20140208-153029-1.sh
  2. make the file executable
  3. run the file in the appropriate terminal
  4. delete the script when it is done executing

AFAIK, the problem is in 3.: this doesn’t solve any problem, as I’d need another termpipe instance to run the first on the appropriate terminal. And one for that one. And another for that, ad infinitum. So this cannot work. Or can it.

Читайте также:  Can connect to localhost linux

The solution could be to use a named pipe per terminal, and when each starts, a script would tell the pipe to forward anything it receives to the terminal, and then to execute it (like a sort of daemon).

I think this might work but I don’t know how to set up the initial script. How can I? How can I tell the FIFO to give piped commands for the respective terminal to run? I don’t know much Bash, so I’d appreciate full explanations.

Источник

linux — write commands from one terminal to another

What are you really trying to do? It may be your logic for trying this is in the first place is flawed; there might be an easier solution to get the same result. Also, terminals run in separate processes so you’d need some form of interprocess communication to get them to talk to one another.

7 Answers 7

#!/usr/bin/python import sys,os,fcntl,termios if len(sys.argv) != 3: sys.stderr.write("usage: ttyexec.py tty command\n") sys.exit(1) fd = os.open("/dev/" + sys.argv[1], os.O_RDWR) cmd=sys.argv[2] for i in range(len(cmd)): fcntl.ioctl(fd, termios.TIOCSTI, cmd[i]) fcntl.ioctl(fd, termios.TIOCSTI, '\n') os.close(fd) 

Is posible to show the output of a command on multiple terminals simultaneously with the following script., and it works with all console programs, including the editors. For example doing:

execmon.bash 'nano hello.txt' 5 

Open an editor and both the output and the text that we introduce will be redirected to the virtual terminal number 5. You can see your terminals:

Each virtual terminal has an associated number.

Is work with the normal terminal, konsole and xterm, just create the file execmon.bash and put this:

#! / bin / bash # execmon.bash # Script to run a command in a terminal and display the output # in the terminal used and an additional one. param = $ # if [$ param-eq 2]; Then echo $ 1 | tee a.out a.out && cat> / dev / pts / $ 2 && exec `cat` a.out | tee / dev / pts / $ 2 && rm a.out else echo "Usage:" echo "execmon 'command' num ' echo "-command is the command to run (you have to enter ')" echo "-num is the number of virtual console to output to the" fi 
execmon.bash 'ls-l' 5 execmon.bash 'nano Hello.txt' 5 

Источник

Оцените статью
Adblock
detector