What is a command-line equivalent of pressing a key on remote computer via ssh
2014-04
What are the options to target specific keys on a remote computer and execute the equivalent of virtually pressing them from the terminal via ssh (what would normally be a user pressing them)?
Example is adjusting the volume:
sudo osascript -e "set Volume 10"
I'm not asking for applescript.
There is some information about how to do that HERE. An excerpt from that page is included below.
Terminals only understand characters, not keys. So al function keys are encoded as sequences of characters, using control characters. Apart from a few common ones that have an associated control character (Tab is
Ctrl+I
, Enter isCtrl+M
, Esc isCtrl+[
), function keys send escape sequences, beginning withCtrl+[ [
orCtrl+[ O
. You can use thetput
command to see what escape sequence applications expect for each function key on your terminal.
Also, Hacker's Keyboard was suggested on the page linked above, if you are attempting to do the same sort of thing from an Android device.
You can run commands over ssh directly.
ssh user@host1 command
will run the command on host1 under the user.
So to use your set volume example, you could do this -
ssh root@host1 osascript -e "set Volume 10"
I want to download files from a remote server to my local drive, and do it from the command line. I also want to be able to do this over SSH. How can I do this?
Note: the remote server is Ubuntu, the local is Mac OS X
Use scp
-command, it runs on top of SSH. Example:
scp [email protected]:/path/to/file localfile
It also works another way round
scp localfile username@host:/path/remotefile
Username, path, and filename can be omitted (but not the :
!).
As Iain said, SFTP works also, but I tend to favor scp
for its cp
-like usage.
I use SFTP for this. It's command line and uses the same security as SSH.
You can also use rsync
for it. It can work over SSH.
If you can't use scp
or SFTP you can use tar
over SSH:
tar cf - . | ssh otherhost "cd /mydir; tar xvf -"
This one is also good if you have sparse files which otherwise will "explode".