Calling expect from shell script which inturn call python

Hi Team,

I have to execute a task from my local machine, where i keep my .expect,.sh, .bash and .python scripts .Task are coded in the script and has to be executed at remote machine.

for that i used following task
.....
SCRIPT 1:

cat shell_check.sh

read value
if [ $value -eq 1]
then
expect sshscriptABC.expect
else
expect sshscript123.expect
fi

.........
SCRIPT 2:

cat sshscriptABC.expect

spawn ssh root@10.56.A.B"bash -s" < ./real.bash
expect "passwd \n"
interact

.......
SCRIPT 3:

cat real.bash

if [ $uname -eq linux ]
then 
./pythonscrip.python
else
echo "fail"

******************************

I came to know when script 1 is executed,script 2 starts executed.Inside script2 we are using ssh and running local script on remote system.

but when script 2 has to execute script3 ,the file is in local system(pythonscript.python) is not getting executed

please can anyone tell me what is going wrong.

how to rectify it???:cool::cool::cool:

SCRIPT 1:-
Note the space after '1' in the square brackets...

read value
if [ $value -eq 1 ]
then
expect sshscriptABC.expect
else
expect sshscript123.expect
fi

SCRIPT 3

if [ "$uname" = "linux" ]
then
python pythonscrip.py
else
echo "fail"
fi

You can't expect the ./pythonscrip.python to be started without the interpreter running or having a shebang referencing python, this assumes Python is in the PATH.
Also python scripts end in '.py' not '.python'; research the extension '.pyc'...
Lastly the python script should match either PRE Python version 3.x.x OR POST Python version 3.x.x or else again it will not do as expected.

HTH

1 Like

Yes Python have extension as .py

but i need to know,once script2 calls for .py internally.then how will the .py script will be invoked .

since .py script is available at local machine only and not in remote machine.
As current control(session) is executing script at remote machine...

..................

Any way to make this happen???

I can't help with the expect script as I know no expect...

You are assuming that the last shell script is being executed. Let's assume that it is......
......then the __partial__ shell script that executes a python script needs uname to work.

Somewhere in this script you have a variable with the same name as the command - not a good idea - and you are assuming the variable '$uname' returns 'linux'. This may or may not be true in all linux flavour cases.

If it is not true then the python script will not be executed.

If it is true and the python script still does not execute then an error report will ensue.

It might br a good idea to capture this error report to a file and act upon it...

HTH.