Sponsored Content
Full Discussion: Expect and interact
Top Forums UNIX for Advanced & Expert Users Expect and interact Post 302934962 by sri243 on Thursday 12th of February 2015 05:21:04 AM
Old 02-12-2015
Expect and interact

I am trying to log on to server as a normal user and then sudo to root.

I am using below expect script.
Code:
[linux@linux]$ cat SC.orig 
expect <<EOF # | tee -a $LOGFILE 
spawn sshpass -p "mypassword" ssh -l myid  nim
expect "$"
send  "sudo su - root\n"
expect "Password:"
send "mypassword\n";
sleep 4
interact 
[linux@linux]$

When I run this .. I get below
Code:
[linux@linux]$ SC.orig 
/home/linux/bin/SC.orig: line 9: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
spawn sshpass -p mypassword ssh -l myid nim
sudo su - root
mypassword
Last unsuccessful login: Fri Jan  9 09:44:23 2015 on ssh from abcxyx
$ sudo su - root
mypassword
Password:
TERM=xterm
<<< 
[nim:/home/root] [linux@linux]$

This script is authenticating me to remote server and then doing sudo to root but then exits from shell and comes back to my local shell.

I want my script to enter passwords and then take me to shell.

Could you please help me with this script ?


Moderator's Comments:
Mod Comment Please use code tags next time for you code and data

Last edited by vbe; 02-12-2015 at 07:16 AM.. Reason: code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can a shell script interact with database?

Hi All, Language like C,Java can interact with database..and can use database information .. can a shall script do this? if yes thn plz guide me..... thankx (7 Replies)
Discussion started by: johnray31
7 Replies

2. Shell Programming and Scripting

Expect - Interact output hangs when large output

Hello, I have a simple expect script I use to ssh to a workstation. I then pass control over to the user with interact. This script works fine on my HP and Mac, but on my Linux Desktop, I get a problem where the terminal hangs when ever I execute a command in the interact session that requires a... (0 Replies)
Discussion started by: natedog
0 Replies

3. UNIX for Advanced & Expert Users

Interact to windows server from unix box

Hello - My requirement is like this... I have flat file which is sitting in windows server... My shell script is running in unix box. Shell script loads the flat file into oracle through sqlloader. So script needs to pickup the flat file from windows box. I need to refer windows location in... (8 Replies)
Discussion started by: govindts
8 Replies

4. Shell Programming and Scripting

How to make shell script interact with program

Hello all! I have a C program that runs on a loop, prompting the user for input until it is exited. I want to create a shell script that can run this program and provide input. How can I do this? I have investigated 'expect' and piping to stdin, but haven't had any success. Any help is... (2 Replies)
Discussion started by: radish04
2 Replies

5. UNIX for Dummies Questions & Answers

Expect "interact" fails when called from another script

So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly. Now I'd like to apply this script... (2 Replies)
Discussion started by: treesloth
2 Replies

6. Shell Programming and Scripting

Expect script exiting too fast if used without interact.

Hi I'm working on an Expect script that is supposed to log-into a remote server and run some steps and exit. In the script I first spawn a 'ssh' session to the server and then after logging in I 'send' all the necessary steps ( with a '\r' at the end, so that they get automatically executed the... (3 Replies)
Discussion started by: clakkad
3 Replies

7. Shell Programming and Scripting

Scripts to Interact with Webpages

Hi, Is it possible to have a script to interact with webpages. I want to create a script that logs a user into a specific site, and is able to get/post information. Would anyone give me instructions on how it's should be done, and where I can find information on starting it out. I know... (2 Replies)
Discussion started by: Pztar
2 Replies

8. Shell Programming and Scripting

can a nohup'ed ksh script interact with user

I have a long running ksh script that I need to run with "nohup" in the backgound which is all well and good but at the very start of the script it needes to output to the screen to query the user and accept a response before continuing. Any thoughts on how to accomplish this other than... (11 Replies)
Discussion started by: twk
11 Replies

9. Shell Programming and Scripting

Expect Scripting - Using the "interact" command?

Hello All, I am writing an Expect Script to execute some commands over ssh then exit the script. The script works just fine if I automate everything and assuming the correct password was entered. So this Expect Script gets executed from a Bash script... From the Bash script I pass along an... (0 Replies)
Discussion started by: mrm5102
0 Replies

10. Shell Programming and Scripting

Expect script - Interact help

Hi Guys, Further to my post yesterday I have got round the issue of not being able to use expect by using one of our unix machines to have the script running instead of the jumpbox itself. However my issue is I now have an extra bit it the script which is shh to the jumpbox which requires a ras... (1 Reply)
Discussion started by: mutley2202
1 Replies
SCRIPT(1)							   User Commands							 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-c command] [-e] [-f] [-q] [-t[=file]] [-V] [-h] [file] DESCRIPTION
script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a, --append Append the output to file or typescript, retaining the prior contents. -c, --command command Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -e, --return Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n. -f, --flush Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can super- vise real-time what is being done using `cat foo'. --force Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic link. -q, --quiet Be quiet. -t, --timing[=file] Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. -V, --version Output version information and exit. -h, --help Output help and exit. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. AVAILABILITY
The script command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux February 2011 util-linux
All times are GMT -4. The time now is 06:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy