Calling expect from shell script which inturn call python


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Calling expect from shell script which inturn call python
# 1  
Old 04-25-2015
Network 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:
Code:
cat shell_check.sh

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

.........
SCRIPT 2:
Code:
cat sshscriptABC.expect

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

.......
SCRIPT 3:
Code:
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???SmilieSmilieSmilie

Last edited by DukeNuke2; 04-25-2015 at 03:07 PM..
# 2  
Old 04-25-2015
Quote:
Originally Posted by Sivarajan N
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:
Code:
cat shell_check.sh

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

.........
SCRIPT 2:
Code:
cat sshscriptABC.expect

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

.......
SCRIPT 3:
Code:
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???SmilieSmilieSmilie
SCRIPT 1:-
Note the space after '1' in the square brackets...
Code:
read value
if [ $value -eq 1 ]
then
expect sshscriptABC.expect
else
expect sshscript123.expect
fi

SCRIPT 3
Code:
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

Last edited by wisecracker; 04-25-2015 at 06:13 PM.. Reason: Typos and missing element.
This User Gave Thanks to wisecracker For This Post:
# 3  
Old 04-26-2015
Network Calling expect from shell script which inturn call python

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???
# 4  
Old 04-28-2015
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use scl enable python command call with in bash shell script?

I have a bash shell script, within it i am using the below two commands . its failing right on scl enable command itself. if i run it by itself without a shell, it works fine. by default it is using pythin version 2.6 something. i want to use 3.4 version for that reason with in the shell... (3 Replies)
Discussion started by: cplusplus1
3 Replies

2. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

5. Shell Programming and Scripting

Calling Expect Script - Telnet

Hi All, I have an Expect script which logs into Cisco switch, performs a show interface command. I want to read a file of ip addresses which will be passed to the expect script. The script to read the file works, the expect script works on it's own but when i call the 'expect' script from the... (12 Replies)
Discussion started by: trinak96
12 Replies

6. Shell Programming and Scripting

Calling Shell Script from Expect...

Hi there, I need some help regarding the execution of shell script from expect as the method I am trying is giving me error. I wrote an shell program which takes two arguments to telnet to a device and saves the output in a file. Following is the script.... (0 Replies)
Discussion started by: cyberparanoid
0 Replies

7. Shell Programming and Scripting

ssh is not working while calling through expect shell script

Hi, Please share you experience and way out on below error:--> #!/bin/bash -xv FILE=login.txt + FILE=login.txt CONNECT=sshlogin.exp + CONNECT=sshlogin.exp SERVERNAME=$1 + SERVERNAME=192.168.12.1 MyServer="" + MyServer= MyUser="" + MyUser= MyPassword="" + MyPassword= exec 3<&0 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

8. Shell Programming and Scripting

How to call expect script from Perl

I have a Perl script sub.pl, and i want to call another Expect script called sub.exp. The sub.exp will generate a text file called sub.txt, while the sub.pl called from a html form will display the content of sub.txt to the textarea on the html form. How do I call sub.exp from sub.pl??? ... (5 Replies)
Discussion started by: cxbest
5 Replies

9. Shell Programming and Scripting

Calling Expect script in Perl...

I call a EXPECT script from my perl script with machine IP and a FIle. The script logins to the machine and exports the value. The values to be exported or stored in a file. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line, Now I could like... (4 Replies)
Discussion started by: ramkriz
4 Replies

10. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies
Login or Register to Ask a Question