exec bash file with putty - windows

I'm trying to execute a bash file with putty/plink but gives me an error.
On windows Ive got this batch:
E:\putty\plink.exe user#link -pw password -m E:\folder\test.sh
on bash file Ive got this:
#!/bin/bash
vtoff
vtadmin check connector /PCS/ConnectionModels/Arbor/
and the error:
C:\folder>e:\folder\test.bat
C:\folder>e:\putty\plink.exe user#link -pw password -m e:\folder\test.sh
ksh[4]: vtoff: not found
ksh[5]: vtadmin: not found
C:\folder>

The documentation for plink says that -m specifies that it should "read remote command(s) from file".
Since #!/bin/bash isn't a command, and your error message references ksh, it's pretty clear that bash is nowhere to be found in this question!
As for your actual error message, it seems that the commands aren't found, probably because they're not in your PATH.

Related

Use PuTTY's -m parameter to run script on login

In the putty manual outlines how to use the program with command line parameters. I have this setup with a shortcut on my toolbar to automatically log me into my server.
"C:\Program Files\PuTTY\putty.exe" username#server -pw .... -C
However, I'd like to run a simple script to automatically put me in a specific directory once I log in. I saw there's the -m command to give "a local file name, and it will read a command from that file".
With a file at the destination I've tried the following options:
"C:\Program Files\PuTTY\putty.exe" username#server -pw .... -C -m "C:\local file\script.txt"
"C:\Program Files\PuTTY\putty.exe" username#server -pw .... -C -m "C:\local file\script.sh"
"C:\Program Files\PuTTY\putty.exe" username#server -pw .... -C -m "/server/file/with/755/permissions/script.sh"
And nothing worked.
I'm trying to find an example of this parameter and use but I can't find one. How can I properly use this parameter.
Quoting the docs,
The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.19.1). However, the -m option expects to be given a local file name, and it will read a command from that file.
And quoting section 4.19.1,
In SSH, you don't have to run a general shell session on the server. Instead, you can choose to run a single specific command (such as a mail user agent, for example). If you want to do this, enter the command in the ‘Remote command’ box.
Note that most servers will close the session after executing the command.
Note the "instead". This is not a command to run in the shell before passing control to you. This is a command to run instead of a shell.
You can't just put cd /wherever and expect to end up in a shell in directory /wherever. You might be able to write a command that will run a shell in the directory you want and give you control, though I'm not sure how to get all the details correct.

run bash script in PowerShell with ssh fails with invalid format

I created a simple bash script that runs fine on Ubuntu 18/20.
Decided to port it onto PowerShell.
I start PowerShell in Windows 10.
Then type: ssh 192.168.1.56
This allows me to reach the target.
(the key is located in /c/users/joe90/.ssh/)
On the other hand, the bash script does the same thing:
#!/bin/bash
ssh 192.168.1.56
Yet, I keep getting this error:
load pubkey "/c/Users/joe90/.ssh/mykey-xyz": invalid format
The only thing I was able to sort out is that typing from PowerShell:
ssh -V
return ==> OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
But when the myBash.sh bash script runs (/usr/bin/bash ...):
ssh -V
return --> OpenSSH_8.3p1 ...
Any thoughts ?
Additional Notes:
The answer seems to lie here. It does ssh onto target but always leave this error mentioned. I tried to make a public key with no success.
Run
/usr/bin/ssh 192.168.1.56
instead (assuming this is the one you want to run).
Verify it using
/usr/bin/ssh -V
form bash, or
sh -c '/usr/bin/ssh -V'
from powershell.
Any time I see "invalid format" while using Windows Subsystem for Linux, I run dos2unix on that file and that seems to clear up a lot of errors. In WSL you just type: dos2unix fileName.txt

How to write bash file for establishing a ssh connection

I tried to write a bash file for establishing a SSH tunnel from Pi 1 to Pi2. I found several guides and did it according to them - so far so good. Everything is working now if I type the following in the terminal:
ssh -i .ssh/key_rsa pi#192.168.0.107
I tried the same line of code in a bash file, but there appears the following error message: „File or Dictionary not found“
My bash Code:
#!usr/bin/bash -f
xterm -title “Terminal1“ -hold -e ssh -i “.ssh/key_rsa“ “ pi#192.168.0.107“
What's the problem here?
Are you running it from inside you $HOME where .ssh/key_rsa is located?
Perhaps set it to use an absolute path like $HOME/.ssh/key_rsa

Linux expect script

I've spent the better part of 8 hours trying to figure this out with google, so I hope this warrants asking here.
I need a script that will auto-enter a password when I try to connect from my lubuntu image in vmware to a physical device connected by usb.
I've tried at least 50 different scripts I've found online, but none of them worked (or even recognised spawn as a command)
This is my script:
#!/usr/expect
spawn CPY2T_old.sh
expect "root#10.9.8.2's password:"
send "ThePassword"
expect eof
The contents of CPY2T_old.sh is
#!/bin/bash
cd hellolinux/src/Exercise$1
scp $2 root#10.9.8.2:
The above bash script works fine, but I have to enter the password, which is what I'm trying to avoid in the first place. The expect script gives the following when I execute in cmd:
spawn: command not found
couldn't read file "root#10.9.8.2's password:": no such file or directory
The program 'send' can be found in the following packages:
* mailutils-mh
* nmh
Try: sudo apt-get install <selected package>
couldn't read file "eof": no such file or directory
I've downloaded mailutils and nmh at least a dozen times by now as well. Elsewhere I read I need to #echo off at the top, but this command isn't recognised and gives an error.
EDIT: I can't do passwordless ssh to this device, so please don't suggest it.
I see 2 errors: first
#!/usr/expect
You want
#!/usr/bin/expect
That should have caused an error: how are you launching your expect script?
Second
send "ThePassword"
You forgot to hit enter
send "ThePassword\r"
#!/usr/bin/expect
set timeout 60
spawn ssh user#ip
expect "user#ip's password: "
send "Password\r"
interact
Note:Please be sure of all scripts are executable with command $ chmod +x #file_name or $ chmod 700 #file_name.
\r to execute
Github link:https://github.com/asarari207/Lunix_sh

Repeated prompt for option while running SCP script

When I run an SCP script
scp -W Scp\password.txt -P 22 server:/file_location
scp -W Scp\password.txt -P 22 server:/file_location
in command prompt I get the following prompt:
Do you want to trust this new host key and continue connecting?
Please type 'no','once', or 'always':
As I attempt to type first letter of any option above, it keeps on repeating and prompts the same thing.
Please type 'no','once', or 'always':
Please type 'no','once', or 'always':
Please type 'no','once', or 'always':
How can I resolve this?
I had this same issue and found that it is resolved by copying and pasting the word you are trying to type in. For me I copied the work always and pasted it into cmd.

Resources