Mobaxterm, "Execute Command" Configuration - ssh

I have a to ask about Mobaxterm, I see that I can configure to my sessions, commands in the field execute command on the settings, but I can't send an enter. I need to execute commands like a cd, or an sh, and also send an enter, but the system don't get any of my options like a \n or \r\n or other that I've found on the web.
There is a way to configure the mobaxterm like the secure CRT, where I can send commands and enter, or expect some text and send the next command?

From the MobaXterm User Manual entry about Execute Command:
Specified command will be executed on the remote server after connect.
You can specify multiple commands and separate them with ";" or "&&".
For instance:
pwd; ls -al; date; uname -a
This should be enough for simple commands, like ls, cd, ...
For more complex uses ("expect some text"), I suggest to write a (Unix format) script and invoke it launching MobaXterm with
MobaXterm <script_file>
For more info, see also: https://blog.mobatek.net/post/mobaxterm-command-lines/

Related

Automated input *through* Putty or SSH, not running or scripting on host

I have a scenario where I need to run a shell command to a unix based appliance frequently from windows (linux could be an option). Because it's an appliance, it doesn't have the full breadth of capabilities that, say, Linux would have. I am using PuTTY to do this (I could use SSH from linux as well) which, I assume will work if I do something like "putty.exe -ssh -2 -l username -pw password -m c:remote.cmd hostname", but that only gets the command started. A user has to manually input the password - it cannot be done through command line, and I'm unaware of the capability to grab input from a file.
Is there a way by which I can automate this through the Putty?. By that I mean, I would like to send the input to the command in Putty like I was there, which would thereby be sent it to the appliance, not run a local script.
Thanks all in advance. Your input is greatly appreciated as we all may learn a little something.
Victor
For automation, use Plink (from PuTTY package). It's a console equivalent of PuTTY. So it supports input redirection:
(
echo password
echo some other input if needed
) | plink username#example.com command

Connect to sqlplus in shell script and run sql script with separate password

I am writing a shell script in Jenkins that logs into a database and runs an sql file. All of the commands are logged to the console, so if I use the simple login method for sqlplus (sqlplus -s $USERNAME/$PASSWORD#connectionstring), the password gets logged, which isn't ideal.
This works:
sqlplus -S ${USERNAME}/${PASSWORD}#connectionstring #sql_update.sql
but the logging on Jenkins shows the command once the values have been substituted:
+ sqlplus user123/pass123#connectionstring #sql_update.sql
To avoid having the password logged, I am trying to use the sqlplus login method where you just provide the username and then get asked to input the password.
I have tried the following, but I am getting ORA-01-17: invalid username/password; logon denied
sqlplus -s ${USERNAME}#\"connectionstring\" <<EOF
${PASSWORD}
sql_update.sql
exit
EOF
Is there something obviously wrong with this?
It's worth noting that simply disabling the console logging isn't an option, as we need it for other things in the script.
Also, the difference between this question and Connect to sqlplus in a shell script and run SQL scripts is that I am asking about providing the password separately.
EDIT I managed to partially resolve the issue thanks to Echo off in Jenkins Console Output. My script now contains set +xbefore the commands are run, which hides the commands. However, I'd still like to know what was wrong with the above, so am leaving this question open for now.

How does scp manages to handle Ctrl+C in sink mode

I'm curious about how does scp handles a situation when a binary file contains escape sequences - and, in particular, the Ctrl+C ("\0x03") character from the programmer's side of view.
I have already tried starting it in sink mode and sending it a "\0x03" character, but it clearly exited upon receiving it:
$ perl -e 'print "\x03"'|xsel
$ scp -t /tmp/somefile.txt
^C
$
However, transfering of a binary file that contains the same character doesn't fails, though I believe that it should.
I have also tried to read the scp.c:source function's source code to see if it attempts to perform any characters escape, but to my surprise it doesn't appears so.
The short answer is that the source scp instance communicates with the sink instance through a clean data pipe. Any byte values can be sent through the pipe, and no bytes receive any special treatment. This is the expected behavior for an ssh "shell" or "exec" channel with no PTY.
For the longer answer, I'm going to restrict this to OpenSSH scp running on unix systems. I assume that's the scenario that you're talking about.
The special behavior of keystrokes like Ctrl-C (interrupt the process) or Ctrl-D (end of file) is provided by the TTY interface. Programs like the ssh server use a unix feature called PTYs (pseudo-ttys) to provide a TTY interface for network clients. When you run a command like scp -t ... within an interactive session, you're running it in the context of a TTY (or PTY), and it's the TTY which would convert a typed Ctrl-C into an interrupt signal. Processes can disable this behavior, but the scp program doesn't do that, because it doesn't need to.
When you run scp in the normal way, like scp /some/local/file user#host:/some/remote/dir, the scp process that you launch runs a copy of ssh to make the connection to the remote system. The actual command that it runs will be something like this (simplified):
ssh user#localhost "scp -t /some/remote/dir"
In other words, it starts a copy of ssh which connects to the remote system and runs another copy of scp.
When ssh is run in this fashion, specifying a command to run on the remote system, it doesn't request a PTY for the channel by default. So the two scp instances will communicate with each other through a clean data pipe with no PTY involved.

How to send control commands using python's Paramiko library

I need to SSH a remote machine and get onto the developer mode. To be specific, I want to execute the command 'Ctrl+gog' upon which I will be prompted for a password. I know how to execute the normal commands, for example chan.send("enable\n"). Please provide me with an answer.
chan.send("\x07\x0F\x07")
Above command worked fine for me.Just concatenate the Hexa equivalent for Ctrl-g,Ctrl-o,Ctrl-g which is, x07x0Fx07.

How to input password on command prompt using VBA?

I've created a procedure on VBA (Excel) that restarts services on remote servers calling the command prompt and executing the "runas" command. I need to enter the command on the servers as administrator. So far it works fine but I don't want to have to type my password for each I want to run the command in. I know how I can automate the task using VBA and the Excel. What I don't know is how could I input my password on the command prompt using VBA?
Can anybody help me?
Thanks.
I've had all sorts of issues trying to convince runas to let me specify passwords from a program.
In the end, I tossed it and downloaded psexec from the Microsoft Windows Sysinternals site, which has other good stuff as well.
While many see this as a tool running remote programs, it can also be used quite happily to run local stuff under a different user name while allowing you to specify the password as a command-line argument, such as:
psexec -d -u USER -p PWD -w WORKDIR EXECUTABLE
You should be able to create a textbox control in VBA with the input mask set to password, this will allow you to enter the password in a non-viewable fashion.
Then you can just construct the psexec command and execute it from VBA, without having to worry about injecting the password into the process running runas.