-
Linux Terminal control
Hello,
probably somebody can help me how control Terminal in Linux.
I don't know what will be best to create to control Terminal(Localhost, SSH). Is possible via Socket launch Terminal and control commands and output? Idea is to connect to terminal and perform some commands take output...to log file and exit? Do you have any Idea what will be a best solution? Thank you,
-
I'm sorry, but I just cannot understand what you wish to accomplish. I cannot tell whether you refer to
- Terminal
a generic name for a number of different applications (x-terminal-emulator, xterm, xfce4-terminal, etc.) that all provide a command-line terminal in most Linux distributions) - Terminal control
via termios interfaces - Terminal libraries
or text-based user interfaces like curses - Creating pseudoterminals
like e.g. screen and expect commands do: they create a pseudo-terminal, and run some other program in that pseudo-terminal. The other program thinks it's being run by the user in a terminal, but both input and output is under full control of your own program. - Connecting to localhost or remote machines via SSH programmatically
so that your own program or script is a stand-in for the user supplying the keypresses to the remote machine
- Via the ssh command-line client (external program)
- Via an ssh library
- Via writing your own ssh client
My instincts do say that your root problem is related to how SSH requires a password. Using a program or a script (or expect) to supply that password is always the wrong path: you should use public keys instead! See here, here, here, or here for guides. If your server does not allow public key authentication, switch to a better server, or complain to your server administrator's boss. If you need noninteractive SSH connections, public keys, fully certificate-based authentication (which is a bit more complicated to set up), and certain even more complex schemes involving Kerberos etc., are the only sane options.
Some recommended reading:
- Pseudoterminals(Wikipedia)
- man 7 pty, Linux pseudoterminal interfaces
- man 1 ssh, the man page of the OpenSSH command-line client (if you want to just have your own program or script replace the user)
- libssh tutorial; in case you want to create your own SSH client
Although all of this looks daunting, it really is not. The above is so massive only because you have a LOT of options to choose from.
In my case, I do a lot of stuff remotely via scripts and commands (having set up SSH keys first). For example, to create a compressed tar ball of /var/www/ on the remote computer, and store the result locally, I can run
Code:
ssh remote.machine tar -cJOC /var/www/ . > remote-www.tar.xz
Or, if the connection is fast and I wish to only gather but not compress the files on that remote machine, I can use
Code:
ssh remote.machine tar -cOC /var/www/ . | xz -z -F xz - > remote-www.tar.xz
Or, if I just want the file listing in a shell variable, I can use
Code:
WWWFILES="$(ssh remote.machine find /var/www -ls)"
Or, if the server has ample CPU power, but the connection is slow, I can save bandwidth by compressing the list on the remote machine and decompress on the local machine using
Code:
WWWFILES="$(ssh remote.machine 'find /var/www -ls | xz -z -F xz -' | xz -d -F xz -)"
If you have a specific task, and preferred language (shell script, Python, C), I should be able to help you choose a straightforward way to solve your actual problem?