Calling WinRS when using a password with spaces - powershell-remoting

I'm trying to call WinRS for some of our automated scripts. I've run into an issue when attempting to pass a password with spaces for the -p argument.
For example,
winrs http://server:5985 -p:my password -u:user dir
fails with the message
winrs.exe:The parameter is incorrect.
Quoting the argument doesn't seem to help,
winrs http://server:5985 -p:"my password" -u:user dir
it fails with the message
Winrs error:Access is denied.
If I type in my password, everything works as expected, however this is not an option for the workflow we're building.
Is it possible to pass a password containing spaces to WinRS? If not, is there a workaround that does not include manual typing?

The host needs to be prefixed by "-r:"
like so:
winrs -r:http://server:5985 -p:my password -u:user "dir"

Try using a backtick before the space. The backtick is powershell's escape character:
winrs http://server:5985 -p:my` password -u:user dir
This should prevent the space from being interpreted as a delimiter.

Try using the caret escape character. I believe one of the following combinations might work:
winrs http://server:5985 ^"-p:my` password^" -u:user dir
or
winrs http://server:5985 -p:^"my` password^" -u:user dir
Courtesy of
https://www.drupal.org/node/1242152

Related

Passing user and password in URL doesn't work

I have some URL like this : X.XXX.XXX.XXX:10080
I tried to add a user and password in this url like this: http://OLM:OLM794$#X.XXX.XXX.XXX:10080
User = OLM
Psw = OLM794$
And it doesn't work
Also when I run : curl http://OLM:OLM794$#X.XXX.XXX.XXX:10080 it shows me :
curl: (6) Could not resolve host:OLM:OLM794X.XXX.XXX.XXX, it removes $# and the port :10080
When I try : curl -u OLM X.XXX.XXX.XXX:10080 then I enter the password, it works, Im able to connecte to that server.
My need is to call my url with user and password like this:
http://OLM:OLM794$#X.XXX.XXX.XXX:10080
But it doesn't work.
I read this solution : Using cURL with a username and password? but I haven't found solution
Have you an idea why ?
It would seem curl parses and reconstructs the URL, leaving out characters that it thinks are illegal. For me, the same command gives a different error though.. It could be that your curl version differs from mine.
$ curl -v http://OLM:OLM794$#127.0.0.1:10000
* Rebuilt URL to: http://OLM:OLM794127.0.0.1:10000/
* Port number ended with 'O'
* Closing connection -1
curl: (3) Port number ended with 'O'
The solution is quite trivial, just url-escape the $ symbol: %24:
$ curl http://OLM:OLM794%24#127.0.0.1:10000
According to RFC1738, the dollar-sign was allowed as an unreserved character and could be directly used, but this old RFC has since been updated many times. RFC3986, for example, does not mention it as an unreserved character anymore. This means the $ symbol has received a special meaning and should be encoded in any URL where it does not serve the function it was given.

Attempting to get rid of binary operator expected error when opening a terminal session

Every time I begin a new terminal session on my Mac, I receive the following error messages:
-bash: [: /Users/angelobrown/wdi/exercises/test_ossicle/google-cloud-sdk: binary operator expected
-bash: [: /Users/angelobrown/wdi/exercises/test_ossicle/google-cloud-sdk: binary operator expected
Can anyone tell me how to fix this so that I no longer experience these messages when beginning a new terminal session? Thanks.
I had this issue and the problem is something unquoted inside the file ~/.bashrc.
This file is executed when bash is opened.
So you should open nano ~/.bashrc and search for directories with folder name spaced.
In my case, my Windows username is name lastname, so I justed quoted it in the file.
Ex:
/mnt/c/users/Foo Bar/something change to '/mnt/c/users/Foo Bar/something'

Mysql database restoring with fab and curses in django

#hosts(['localhost'])
def start():
import curses
screen = curses.initscr()
backup_file = db_backup.sql
local("mysql -u %s -p %s < " % (
db_username,db_name) + backup_file)
now I run this with fab start
it asks for a password, after I entered the password the screen is not responding.
Can anyone know what's happening here? if I remove curses it is working fine.
The local command is doing the prompt for the password. That expects that the terminal modes are set normally, so that if you press Enter (which sends a ^M) it is mapped into a newline (^J).
When you initialized curses using curses.initscr, that changes the terminal modes so that the mapping is not done. The curses library does its own mapping when you call getch.
If you press controlJ rather than Enter, that should appease the password prompt in the local command.
Since your example is not using curses (perhaps it does later) you can either omit it, or move the initialization down to the place where you need to use it.
In any case, you probably cannot make the local command use a password prompt in the script via curses (without assuming and relying upon special devices).
By suspending the curses, it will return to the terminal. where we can complete the restore database task.

Error passing large text with special characters in a variable to MYSQL

I have an script that connects with SSH to a remote Host, and executes another script there which inserts data into a local MySQL database. I pass all the variables that need to be inserted within the SSH. All works fine excepts for the $textBody variable.I think the problem is that there ara a lot of text in this variable (included special characters that may be causing the error).
ssh -p 22 $user#$IP_ADDRESS "$SCRIPTMYSQL \"$taulaName\" \"$valueType\" \"$valueTitle\" \"$textBODY\" exit"
This is the error I get:
jailshell: -u: command not found
ERROR at line 1: Unknown command '\S'.
If I pass another variable different than $textBODY in his place, no error occurs.
I'm passing double quotes inside the variable.
If $textBODY doesn't contain single quotes ', you can use them:
ssh -p 22 $user#$IP_ADDRESS "$SCRIPTMYSQL \"$taulaName\" \"$valueType\" \"$valueTitle\" '$textBODY' exit"
(that also applies to the other variables, of course).

How to suppress exp_spawn translating " to \?

I am using tcl8.5 on windows 7. I need to use spawn with openssh. The username has double-quotes (e.g. abc"). I can use openssh to login the remote device with this account when I am using it in a command window:
D:\Program Files\OpenSSH\bin>ssh 192.168.0.253 -labc"\""
...
abc"#192.168.0.253's password:
(the correct username is displayed by openssh)
However, when I use spawn ssh with the same syntax in a script, the " is translated to \
When I enter the correct password, access is denied.
exp_spawn "$sshClient" "192.168.0.253" -labc\"\\\"\"
=>
abc\\""#192.168.0.253
The following attempt also shows " being translated to \
exp_spawn "$sshClient" "192.168.0.253" -labc\"
=>
abc\#192.168.0.253
Could anyone show me the correct syntax please? Or is there any option in exp_spawn I need to enable?
Try
exp_spawn $sshClient 192.168.0.253 {-labc"}