Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Problem with script trying to SSH into a linux server and being able to su –

$
0
0

I am trying to write a script for work to automate tasks for several servers. I need access to several ID’s. Several of these ID’s I am able to “sudo su – <account>” which makes the task easy. Some ID’s I need to su – <account>. being able to switch users with a password prompt is giving me issues. My plan originally was to leave an expect script onto the server and to just execute it, I’ve been told I’m not allowed to do that. So I’ve tried to run the expect command via plink but it’s giving me strange results.

Here is the SSH part of the script:

$plink = “C:Program FilesPuTTYplink”

set-alias plink $plink

$cmd = @(“expect”,

“spawn /bin/su – testuser0”,

“expect ‘Password:'”,

“send ‘q1w2e3r4r;'”

“interact”,

“whoami”)

$cmd|plink -ssh -pw q1w2e3r4 testuser1@192.168.56.101

here is the output from the console.

]0;testuser1@***: ~testuser1@**:~$ expect expect1.1> expect1.1> spawn /bin/su – testuser0

4215

expect1.2> expect1.2> Password: expect1.3> expect1.3> invalid command name “‘” while executing “‘”

So my question is: is my syntax wrong? Does anyone know a better way to be able to Su , while using plink from a powershell script?

submitted by /u/dawgthebootyhuntr
[link] [comments]

The post Problem with script trying to SSH into a linux server and being able to su – appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles