I need to emulate a key into a particular process running, i have no control about it's source code and Xserver isn't running, I believe the proc is using directfb to handle keyboard inputs.
You should be able to open a virtual terminal (fire a 'man 7 pty' to read the docs).
You can also run the app inside a detached screen and use the 'stuff' command to send input to the virtual window. Try it on the command line:
Start the application:
$ screen -S sessioname -d -m /path/command
Send input:
$ screen -S sessioname -X stuff 'input line 1
input line 2
...
input line n
'
Related
I have a PS script right now that lets me log into a range of switches one after another.
70..80 | % { plink "172.16.15.$_" -l enterusername -pw enterpassword}
This allows me to start at switch ending in .70 and once I am done and type exit, it automatically logs into the next one in sequence.
I want to create a text file that contains the changes I want to make to the running-config on the switch, such as maybe adding a user to 100 or so switches. How can I add to the PS script to make it so that it applies the changes to the config contained in the created text file? I am trying to automate changes to 100 edge switches vs having to type the config into each switch.
Or instead of pointing to a text file, can I somehow add the changes for the switch config right into the PS script?
When in doubt, read the documentation (emphasis mine):
7.2 Using Plink
This section describes the basics of how to use Plink for interactive logins and for automated processes.
Once you've got a console window to type into, you can just type plink on its own to bring up a usage message. This tells you the version of Plink you're using, and gives you a brief summary of how to use Plink:
Z:\sysosd>plink
PuTTY Link: command-line connection utility
Release 0.53
Usage: plink [options] [user#]host [command]
("host" can also be a PuTTY saved session name)
Options:
-v show verbose messages
-load sessname Load settings from saved session
-ssh -telnet -rlogin -raw
force use of a particular protocol (default SSH)
-P port connect to specified port
-l user connect with specified username
-m file read remote command(s) from file
-batch disable all interactive prompts
So all you need to do is create your command file, and add it to the commandline:
70..80 | ForEach-Object {
plink "172.16.15.$_" -l enterusername -pw enterpassword -m 'C:\commands.txt'
}
My question is regarding the way the file ("-m" switch) is used by Plink.
My command is:
plink.exe -ssh admin#10.20.30.1 -pw p#ss30rd -m commandfile.txt
I'm trying to connect to a switch and execute these 3 commands:
system-view
user-interface vty 0
screen-length 200
The issue here, is that each command depends on it's predecessor. In other word, executing the command system-view gives access to a new level or a context where the second command user-interface vty 0 can be valid and executed and same thing for the third command in which is only valid (and available) only if user-interface vty 0 is executed
Is there a way or a workaround that we can achieve this using Plink?
My goal here is to put the "Plink" command line in a script and try to analyse the output
Thanks in advance
If you specify multiple commands using the -m switch, they are executed one after another. While you (if I understand you correctly) want to execute the commands within each other. That's not possible with the -m switch.
What you can do, is to feed the commands to Plink using an input redirection. This way, Plink behaves, just as, if you typed those commands.
(
echo system-view
echo user-interface vty 0
echo screen-length 200
) | plink.exe -ssh admin#10.20.30.1 -pw p#ss30rd
Note that by default, with the -m switch, Plink does not allocate a pseudo terminal, while with the input redirection, it does. So the behavior is not identical. You can use the -t/-T switches to override that.
Here is what I am trying to achieve:
run a matlab command/script that starts a unix terminal and from within that terminal starts external software. Matlab itself should be decoupled from that shell immediately.
On a Unix system, I am currently trying to start an external program from within matlab. I know that I can basically use the matlab command prompt as a terminal by adding an ! in front of every command. However then, the program's output is also displayed within on the matlab command prompt and the program is killed as soon as matlab is closed.
To start an external terminal, call that terminal emulator using the matlab system command. If gnome-terminal is your terminal:
system('gnome-terminal');
To pass parameters to the terminal use -e
system('gnome-terminal -e echo hello World');
This terminal will close immediately after it's finished running. So too keep it open:
system('gnome-terminal -e "bash -c \"echo Hello World; exec bash\""');
Hope this helps. I similar command should work for other terminal emulators beside gnome-terminal.
I am having a strange issue. I have written a script which is basically running a perl script in remote server using ssh.
This script is working fine but after completion of the above operation it will ask user to choose the next operation.
it is showing the options in the command prompt but while I am giving any input it is not showing in the screen even after hitting enter also it remain same.
I am not getting what is the exact issue, but it seems there is some issue with the ssh command because if I am commenting out the ssh command it is working fine.
OPERATION:
print "1: run the script in remote server \n2: Exit\n\nEnter your choice:";
my $input=<STDIN>;
chomp($input);
..........
sub run_script()
{
my $com="sshg3.exe server -q --user=user --password=pass -exec script >/dev/null";
system("$com");
goto OPERATION;
}
after completing this ssh script it is showing in screen:
1: run remote script
2: exit
Enter your choice:
but while I am giving any input it is not displaying in the screen until and unless I am exiting it using crtl C.
Please can anyone help what might be the issue here ?
One of the classic gotchas with ssh is this - that it normally runs interactively, and as such will attach STDIN by default.
This can result in STDIN being consumed by ssh rather than your script.
Try it with ssh -n instead.
You can redirect the output in command prompt if -n option is not available for you.
try this one it might work for you.
system("$com />null");
As per https://support.ssh.com/manuals/client-user/62/sshg3.html there is an option for redirecting input use --dev-null (*nix) or --null (Windows).
-n, --dev-null (Unix), -n, --null (Windows)
Redirects input from /dev/null (Unix) and from NUL (Windows).
In Unix, I have a process that I want to run using nohup. However this process will at some point wait at a prompt where I have to enter yes or no for it to continue. So far, in Unix I have been doing the following
nohup myprocess <<EOF
y
EOF
So I start the process 'myprocess' using nohup and pipe in a file with 'y' then close the file. The lines above are effectively three seperate commands - i.e. I hit enter on the first line in UNIX, then I get a prompt where I enter 'y' and then press enter to then finally type 'EOF' and hit return again.
I want to know execute this in Perl but I am not sure how I can execute this command as it is over three lines. I don't know if the following will work....
my $startprocess = `nohup myprocess <<EOF &
y
EOF
`
Please help - thank you!
I think your proposal will work as is. If not, try replacing the redirect with a pipe:
my $startprocess = `(echo "y" | nohup myprocess) &`;
Also, depending on WHY you are doing a nohup, please look at the following pure Perl daemonizing approach using Proc::Daemon : How can I run a Perl script as a system daemon in linux?
Expect for interactive programs can be used as well.