Topic "First time use of WinSCP, executecommand hanging"

Author Message
Rob G

Guest


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
Advertisements
Rob G

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Rob G wrote:
Still, need a way to see what's going on in the remote console

Use Output property of CommandExecutionResult returned by Session.ExecuteCommand:
http://winscp.net/eng/docs/library_commandexecutionresult
rgaetan
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
I get WinSCP.ExecuteCommandResult back. This is the command I send: Console.WriteLine(.ExecuteCommand("./update.sh"))
baixue
[View user's profile]

Joined: 2014-03-29
Posts: 1
Location: USA
Hi.
Have you tried calling su update yet?
rgaetan
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
baixue wrote:
Hi.
Have you tried calling su update yet?


Yes, it blows up, anything with su or sudo
rgaetan
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
_________________
Martin Prikryl
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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:
http://winscp.net/eng/docs/faq_su
rgaetan
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
prikryl 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:
http://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.
rgaetan
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
rgaetan wrote:
prikryl 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:
http://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
[View user's profile]

Joined: 2014-03-25
Posts: 16
Location: Decatur, IL
rgaetan wrote:
rgaetan wrote:
prikryl 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:
http://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))
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License