Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

rgaetan

rgaetan wrote:

rgaetan wrote:

martin wrote:

rgaetan wrote:

Yes, it blows up, anything with su or sudo

You definitely cannot call su this way. You can only execute simple commands that quit after completing their task. That's not the case of su. A sudo may work, but there are lot of limitations, see:
https://winscp.net/eng/docs/faq_su


The update.sh script has several odd-timed sequence of commands that execute one after the other, and I can't call them individually because I don't know when they are going to end. So I put them in the update shell. If I use su or sudo in front of it, then, it blows up. I'm not good with Linux, and don't know how to retrieve output, I've tried, but don't know how to make the call. This is the logic behind the code.


OK, I figured it out. Took a chance it would work, and did the following:
Console.WriteLine(.ExecuteCommand("./update.sh").Output)


FYI: I was getting output all run-together, so I changed the code to this:
Str = (.ExecuteCommand("./update.sh").Output).Replace(Chr(10), Chr(13) & Chr(10))
rgaetan

rgaetan wrote:

martin wrote:

rgaetan wrote:

Yes, it blows up, anything with su or sudo

You definitely cannot call su this way. You can only execute simple commands that quit after completing their task. That's not the case of su. A sudo may work, but there are lot of limitations, see:
https://winscp.net/eng/docs/faq_su


The update.sh script has several odd-timed sequence of commands that execute one after the other, and I can't call them individually because I don't know when they are going to end. So I put them in the update shell. If I use su or sudo in front of it, then, it blows up. I'm not good with Linux, and don't know how to retrieve output, I've tried, but don't know how to make the call. This is the logic behind the code.


OK, I figured it out. Took a chance it would work, and did the following:
Console.WriteLine(.ExecuteCommand("./update.sh").Output)
rgaetan

martin wrote:

rgaetan wrote:

Yes, it blows up, anything with su or sudo

You definitely cannot call su this way. You can only execute simple commands that quit after completing their task. That's not the case of su. A sudo may work, but there are lot of limitations, see:
https://winscp.net/eng/docs/faq_su


The update.sh script has several odd-timed sequence of commands that execute one after the other, and I can't call them individually because I don't know when they are going to end. So I put them in the update shell. If I use su or sudo in front of it, then, it blows up. I'm not good with Linux, and don't know how to retrieve output, I've tried, but don't know how to make the call. This is the logic behind the code.
martin

rgaetan wrote:

Yes, it blows up, anything with su or sudo

You definitely cannot call su this way. You can only execute simple commands that quit after completing their task. That's not the case of su. A sudo may work, but there are lot of limitations, see:
https://winscp.net/eng/docs/faq_su
martin

Re: ExecuteCommand hanging

rgaetan wrote:

I get WinSCP.ExecuteCommandResult back. This is the command I send: Console.WriteLine(.ExecuteCommand("./update.sh"))

Obviously. The CommandExecutionResult is object. You need to print its Output property.
rgaetan

rgaetan wrote:

baixue wrote:

Hi.
Have you tried calling su update yet?


Yes, it blows up, anything with su or sudo

Here's what the code looks like now:

For Each Argument As String In My.Application.CommandLineArgs
With SessionOptions
.AddRawSettings("SendBuf", "262144")
.AddRawSettings("SshProt", "3")
.AddRawSettings("Shell", "bash")
.GiveUpSecurityAndAcceptAnySshHostKey = True
.HostName = Argument
.Password = Pwd
.PortNumber = 22
.Protocol = WinSCP.Protocol.Scp
.UserName = "blahblah"
End With ' d

With Session
.DisableVersionCheck = False
.ExecutablePath = "C:\Program Files (x86)\WinSCP\WinSCP.exe"
.IniFilePath = "C:\Program Files (x86)\WinSCP\WinSCP.ini"
.SessionLogPath = "C:\Scheduler\Session.log"
.DebugLogPath = "C:\Scheduler\Debug.log"
.Open(SessionOptions)
Console.WriteLine(.ExecuteCommand("./update.sh"))
End With
Next
rgaetan

baixue wrote:

Hi.
Have you tried calling su update yet?


Yes, it blows up, anything with su or sudo
baixue

Hi.
Have you tried calling su update yet?
rgaetan

Re: ExecuteCommand hanging

I get WinSCP.ExecuteCommandResult back. This is the command I send: Console.WriteLine(.ExecuteCommand("./update.sh"))
Rob G

ExecuteCommand hanging

OK, I authorized update.sh and dropped both su and sudo, now it works. Still, need a way to see what's going on in the remote console
Rob G

First time use of WinSCP, executecommand hanging

It's my first time using WinSCP in VisualBasic 2010, and I know little if anything about Linux. Using WinSCP 5.5.2. Trying to execute sequential commands in Red Hat, shown below. If I send "su" or "call," it errors out with "command xx failed with return code 1 and error message standard in must be a tty." If I use "sudo su" instead, code hangs there forever until it times out, but doesn't error out.

Also, I can't seem to get anything to work to see the remote console or what's going on the Red Hat screen when I send it commands. What code can I use to see console text for the executecommand action? Sorry, a lot of questions. Here's the code:

Dim SessionOptions As New SessionOptions
Dim Session As Session = New Session

With SessionOptions
' .SshPrivateKeyPath = "C:\Program Files(x86)\WinSCP\Private Key.ppk"
.AddRawSettings("SendBuf", "262144")
.AddRawSettings("SshProt", "3")
.AddRawSettings("Shell", "bash")
.GiveUpSecurityAndAcceptAnySshHostKey = True
.HostName = "GTCTCENT1"
.Password = Pwd
.PortNumber = 22
.Protocol = WinSCP.Protocol.Scp
.UserName = "stuff"
End With

With Session
.DisableVersionCheck = True
.SessionLogPath = "C:\Scheduler\Session.log"
.DebugLogPath = "C:\Scheduler\Debug.log"
.Open(SessionOptions)
.ExecuteCommand("su")
.ExecuteCommand("call ./update.sh")
System.Threading.Thread.Sleep(500) ' Wait half a second
.ExecuteCommand("close")
.ExecuteCommand("exit")
End With