LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   run expect script within another script (https://www.linuxquestions.org/questions/linux-newbie-8/run-expect-script-within-another-script-857000/)

ajeesh.tr 01-18-2011 05:12 AM

run expect script within another script
 
I want to run an expect script generated using autoexpect within another script,the expect script has to go into super user mode execute some commands and then exit and come back to user mode.When the script is run in the command line it works fine,i want the script to run within another script.How to go about it..?

GlennsPref 01-18-2011 08:18 PM

Hi,

This may be easily done with sudo.

But you need to have sudo set up first.

I don't know off-hand how to do this without sudo, or being root.

But with sudo,

Code:

#!/bin/bash

...some commands... as normal user..

sudo Expect--commands
exit

more user commands...

the exit line will exit su (substitute user) mode and return to the users bash command.
Hope this helps, Glenn

GlennsPref 01-18-2011 08:32 PM

here is a good su example.
su -c expect...
http://www.linuxquestions.org/questi...script-396938/

cheers Glenn

ajeesh.tr 01-19-2011 02:49 AM

Quote:

Originally Posted by GlennsPref (Post 4229466)
Hi,

This may be easily done with sudo.

But you need to have sudo set up first.

I don't know off-hand how to do this without sudo, or being root.

But with sudo,

Code:

#!/bin/bash

...some commands... as normal user..

sudo Expect--commands
exit

more user commands...

the exit line will exit su (substitute user) mode and return to the users bash command.
Hope this helps, Glenn

i got what you are saying but i dont want to add the root user commands in the same file,i have put those in a different file and i want to call that file in the main file.

GlennsPref 01-19-2011 03:05 AM

Hi.

if you want to call a script from another script, just add a line

(sh /absolute/address/to/script/script.name)

pointing to the script from your initial script.

Is that going to work for your situation?

I guess you have read this, post #2 of http://www.linuxquestions.org/questi...8/#post2017678

Cheers Glenn

ps. I'm still learning, :-)

ajeesh.tr 01-20-2011 06:56 AM

Quote:

Originally Posted by GlennsPref (Post 4229810)
Hi.

if you want to call a script from another script, just add a line

(sh /absolute/address/to/script/script.name)

pointing to the script from your initial script.

Is that going to work for your situation?

I guess you have read this, post #2 of http://www.linuxquestions.org/questi...8/#post2017678

Cheers Glenn

ps. I'm still learning, :-)


I tried what you said stils it is not working,am getting a error
syntax error near unexpected token `;'
;# script wasn't run conservatively originally'

GlennsPref 01-20-2011 05:57 PM

You'll need to debug your code.

I have many scripts that call other scripts, I try to keep them as simple as possible.

Each script should work on it's own, as you said before.

Make sure you are using the right kind of quoting to match your shell type. ie, zsh, bash etcetera.

ajeesh.tr 01-21-2011 05:35 AM

Quote:

Originally Posted by GlennsPref (Post 4232271)
You'll need to debug your code.

I have many scripts that call other scripts, I try to keep them as simple as possible.

Each script should work on it's own, as you said before.

Make sure you are using the right kind of quoting to match your shell type. ie, zsh, bash etcetera.

The issue is solved,error was in my script not in calling the script ,thank you


All times are GMT -5. The time now is 02:46 AM.