LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2011, 06:12 AM   #1
ajeesh.tr
Member
 
Registered: Jan 2011
Posts: 37

Rep: Reputation: 0
Question 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..?
 
Old 01-18-2011, 09:18 PM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Posts: 3,366
Blog Entries: 33

Rep: Reputation: 216Reputation: 216Reputation: 216
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

Last edited by GlennsPref; 01-18-2011 at 09:28 PM. Reason: remove space in bash bang
 
Old 01-18-2011, 09:32 PM   #3
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Posts: 3,366
Blog Entries: 33

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

cheers Glenn
 
Old 01-19-2011, 03:49 AM   #4
ajeesh.tr
Member
 
Registered: Jan 2011
Posts: 37

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by GlennsPref View Post
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.
 
Old 01-19-2011, 04:05 AM   #5
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Posts: 3,366
Blog Entries: 33

Rep: Reputation: 216Reputation: 216Reputation: 216
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, :-)
 
Old 01-20-2011, 07:56 AM   #6
ajeesh.tr
Member
 
Registered: Jan 2011
Posts: 37

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by GlennsPref View Post
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'
 
Old 01-20-2011, 06:57 PM   #7
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Posts: 3,366
Blog Entries: 33

Rep: Reputation: 216Reputation: 216Reputation: 216
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.
 
Old 01-21-2011, 06:35 AM   #8
ajeesh.tr
Member
 
Registered: Jan 2011
Posts: 37

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by GlennsPref View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 04:29 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 10:34 AM


All times are GMT -5. The time now is 12:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration