Problem running shell script in linux using 'call' cmd in c#

Advertisement

eliba3
Guest

Problem running shell script in linux using 'call' cmd in c#

Problem running shell script in linux using 'call' cmd in c#:

I have run the following command to run shell script but nothing happened:

winscp.StandardInput.WriteLine("option batch abort");
winscp.StandardInput.WriteLine("option confirm off");
winscp.StandardInput.WriteLine("open ilvqa1");
winscp.StandardInput.WriteLine("a1234") ;
winscp.StandardInput.WriteLine("a1234") ;
winscp.StandardInput.WriteLine("ls") ;
winscp.StandardInput.WriteLine("cd /")
winscp.StandardInput.WriteLine("call /home/Versions/4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script")

Actually Run_script.sh is not run, Can u please help me solving this issue

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem running shell script in linux using 'call' cmd in c#

First, you probably wanted to do:
winscp.StandardInput.WriteLine("open a1234:a1234@ilvqa1");
instead of:
winscp.StandardInput.WriteLine("a1234") ;
winscp.StandardInput.WriteLine("a1234") ;

If this does not help, please post a log file.

Reply with quote

eliba3
Guest

Re: Problem running shell script in linux using 'call' cmd in c#

I have success connected to linux vm. so I think that the issue is not the connection.

I have a confidence problem to send you the log file:

Can u please just tell me if the following command is proper syntax for running shell script in c#?

winscp.StandardInput.WriteLine("call /home/Scripts/Run_script.sh");

( Remark I have run chmod 777 Run_script.sh before run this cmd )

Reply with quote

eliba3
Guest

Re: Problem running shell script in linux using 'call' cmd in c#

I have attached log.xml:

<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="https://winscp.net/schema/session/1.0" name="pass@ilvq6n" start="2012-02-14T07:13:04.270Z">
<upload>
<filename value="c:\Run_script.sh" />
<destination value="/home/pass/QA/Versions/DD_4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script.sh" />
<result success="true" />
</upload>
<touch>
<filename value="/home/pass/QA/Versions/DD_4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script.sh" />
<modification value="2012-02-13T15:06:48.000Z" />
<result success="true" />
</touch>
<chmod>
<filename value="/home/pass/QA/Versions/DD_4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script.sh" />
<permissions value="rwxrwxrwx" />
<result success="true" />
</chmod>
<call>
<command value="/home/pass/QA/Versions/DD_4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script.sh" />
<destination value="/" />
<erroroutput value="Process Completed" />
<result success="false">
<message>Command '/home/pass/QA/Versions/DD_4.0.1.2/DBScripts/InfrastructureUtility/bin/Run_script.sh'
failed with return code 0 and error message
Process Completed.</message>
</result>
</call>
</session>

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem running shell script in linux using 'call' cmd in c#

eliba3 wrote:

winscp.StandardInput.WriteLine("call /home/Scripts/Run_script.sh");
Yes that's correct.

As you can see from the log file, there's no actual problem. Just that WinSCP considers remote commands that has any error output as failed.
I'll change with in the next release:
https://winscp.net/tracker/797

As a workaround, you can meanwhile do:
call /home/Scripts/Run_script.sh 2>&1
(the 2>&1 redirects error output to standard output)

Reply with quote

Advertisement

Guest

Re: Problem running shell script in linux using 'call' cmd in c#

I have used your workaround. it works. Thanks

I have another question:

My shell script contains several sub shell commands:

i.e.
Run_script.sh file contains:
==============
. ./Param.sh

cd "Internal"

./Installer1.sh
./Installer2.sh

cd ../
==============
The issue is that when running Run_script.sh
( remark: Param.sh is in same work directory as Run_script.sh, and Installer1/2.sh are in internal directory. ( one directory down )

I got the following errors:

<call>
<command value="/home/Installers/Run_script.sh 2&gt;&amp;1" />
<destination value="/home/" />
<output value="/home/Installers/Run_script.sh: line 3: ./Param.sh: No such file or directory
/home/Installers/Installer1.sh: line 5: cd: Internal : No such file or directory
/home/Installers/Installer1.sh: line 7: ./Installer1.sh: No such file or directory
/home/Installers/Installer2.sh: line 8: ./Installer2.sh: No such file or directory" />
<result success="true" />
</call>

My question is: I thought that when running a shell script it will run also all sub shell scripts in the file(Run_script.sh). Same as running it from Terminal console in winscp.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem running shell script in linux using 'call' cmd in c#

Anonymous wrote:

My question is: I thought that when running a shell script it will run also all sub shell scripts in the file(Run_script.sh). Same as running it from Terminal console in winscp.
Sure it does. That's why you are getting the errors.
Your script expects to be run with /home/Scripts/ as current working directory.
So you have to change to this directory before executing call:
winscp.StandardInput.WriteLine("cd /home/Scripts/");
winscp.StandardInput.WriteLine("call Run_script.sh");

Reply with quote

Guest

Re: Problem running shell script in linux using 'call' cmd in c#

Thanks. It finally works. Great !!!

Just for your info:

I got to enter the full path of the shell script although the "cd" cmd before, like:

winscp.StandardInput.WriteLine("cd /home/Scripts/");
winscp.StandardInput.WriteLine("call /home/Scripts/Run_script.sh");

If NOT, I got the following error:

<call>
<command value="Run_script.sh" />
<destination value="/home/Scripts/" />
<erroroutput value="-bash: line 6: Run_script.sh: command not found" />
<result success="false">
<message>Command 'Run_script.sh'
failed with return code 127 and error message
-bash: line 6: Run_script.sh: command not found.</message>
</result>
</call>

Reply with quote

Guest

Re: Problem running shell script in linux using 'call' cmd in c#

I still got the following error in latest winscp version 4.3.7:

<call>
<command value="&quot;/home/Versions/4.0.2.0/DB Scripts/Infrastructure Utility/bin/SIS_CREATE_SH_FILES.sh&quot;" />
<destination value="/home/Versions/4.0.2.0/DB Scripts/Infrastructure Utility/bin" />
<erroroutput value="Process Completed
Process Completed" />
<result success="false">
<message>Command '&quot;/home/Versions/4.0.2.0/DB Scripts/Infrastructure Utility/bin/SIS_CREATE_SH_FILES.sh&quot;'
failed with return code 0 and error message
Process Completed
Process Completed.</message>
</result>
</call>

Remark: I have pot the command in quot - for space 'DB Scripts'.

Is this issue should be resolved in latest version ?

Reply with quote

Advertisement

eliba3
Guest

Re: Problem running shell script in linux using 'call' cmd in c#

I have run the following sh file:
call /home/4.0.2.1/DB Scripts/Oracle/SIS_Run_Script_On_DB.sh 2>&1

SIS_Run_Script_On_DB.sh contains:
sqlplus QA_APP/pas@Server @Install_oracle.sql >> SISLog.log

I got the following error:

<call>
<command value="&quot;/home/4.0.2.1/DB Scripts/Oracle/SIS_Run_Script_On_DB.sh&quot; 2&gt;&amp;1" />
<destination value="/home/4.0.2.1/DB Scripts/Oracle" />
<result success="false">
<message>Terminated by user.</message>
</result>
</call>

What the meaning of "Terminated by user." ?
( Maybe this is the disconnect of sqlplus from the server)
Remark: Actually the SIS_Run_Script_On_DB.sh file run ok but the issue is that I cannot continue running command after this error

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem running shell script in linux using 'call' cmd in c#

eliba3 wrote:

I got the following error:

<call>
<command value="&quot;/home/4.0.2.1/DB Scripts/Oracle/SIS_Run_Script_On_DB.sh&quot; 2&gt;&amp;1" />
<destination value="/home/4.0.2.1/DB Scripts/Oracle" />
<result success="false">
<message>Terminated by user.</message>
</result>
</call>
Can you send me an email, so I can send you back a debug version of WinSCP to track the problem? Please include link back to this topic in your email. Also note in this topic that you have sent the email. Thanks.

You will find my address (if you log in) in my forum profile.

Reply with quote

lpunix
Guest

Problem running shell script in linux using 'call' cmd in c#

how did you use this "winscp" and include it in your projeect??
can you please give me a hint about this..
i've used "ChilkatDotNet2.dll" but got problem if any other file is included in the script which i'm running from my c# code....

I says that "FILE IS NOT FOUND IN THAT PATH"....
will you give some help for winscp... :idea: :idea:

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem running shell script in linux using 'call' cmd in c#

lpunix wrote:

how did you use this "winscp" and include it in your projeect??
can you please give me a hint about this..
i've used "ChilkatDotNet2.dll" but got problem if any other file is included in the script which i'm running from my c# code....

I says that "FILE IS NOT FOUND IN THAT PATH"....
will you give some help for winscp... :idea: :idea:
Nowdays, wou should use WinSCP .NET assembly, not the approach shown in this thread.
See https://winscp.net/eng/docs/library

Reply with quote

sheauyun
Joined:
Posts:
12

Re: Problem running shell script in linux using 'call' cmd in c#

How was this solve at the end? I think I face similar problem and have no idea to turn it around.

Reply with quote

Advertisement

You can post new topics in this forum