Difference between using Here document and Expect in scripts


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Difference between using Here document and Expect in scripts
# 1  
Old 05-19-2011
Difference between using Here document and Expect in scripts

Hi,

I am confused between using here document and using expect for writing interactive shell scripts(like changing password ,FTP or doing su).
My questions are :
1)Why here documents cant change password from shell script.
2)Why we need to use expect for same?
3) Can Sourcing a script can do FTP or change password? like
Code:
. myscript.ksh

or
Code:
source myscript.ksh

4) What is the difference in all three behaviors(here,expect and source)?

Tried to resolve these on own but still i am confused.

Thanks
# 2  
Old 05-19-2011
In order to change a password or run sftp with an 'interactive' password requires that the process breaks off from the parent and becomes a session leader. The session has no attached tty.

This is what a daemon process and expect do.

passwd and sftp and ssh are designed to prevent security breaches. Putting a password in plaintext in a script is a security breach

Go here:
http://www.rite-group.com/rich/ssp/index.html

download the source code, find the pty.c program under the pseudo_term directory -- this is what expcect does so that people can get around the inbuilt security of passwd for example.

Last edited by jim mcnamara; 05-19-2011 at 08:59 AM..
# 3  
Old 05-19-2011
Thanks jim .
But for sourcing no sub shell is created and it runs in parent shell.
So why script run as sopurce cant be used to change shell?

Is it that when i issue passwd command on machine, a new process is created to assist it ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Understanding the difference between individual BASH login scripts

Hello... and thanks in advance for reading this or offering me any assistance I'm trying to understand specific differences between the various login scripts... I understand the differences between interactive vs non-interactive and login vs non-login shells... and that's not where my question... (4 Replies)
Discussion started by: bodisha
4 Replies

2. Shell Programming and Scripting

Scripts triggered via 'expect' - stderr lost

I have a bash script on server that runs fine when run interactively and writes stderr output to a file. However, when invoked through a 'expect' script run on Mac OS my laptop which does ssh to the server : generates the expected file, but file has no content. I suspect the stderr is getting... (1 Reply)
Discussion started by: sdudc
1 Replies

3. Shell Programming and Scripting

Using Expect scripts to port files to different unix box

Hello all, I've been trying to design a script which will help me transfer files from one unix box to another. Following is the code: #!/usr/local/bin/expect spawn /usr/bin/scp ms_cp5_daily.ksh userid@cat:/prod/env/ms.txt set pass xxxxxx expect { password: {send "$pass\r";... (4 Replies)
Discussion started by: sethmj
4 Replies

4. Shell Programming and Scripting

Execution difference in perl scripts for windows / AIX

Hi, I have perl script abc.pl which runs perfectly fine on windows ( execution from cmd). Now i tried to execute the same perl module on the AIX server after defining the captureoutput.pm and other relevant changes. But its behaving very weirdly as a portion of the URL which is formed by... (3 Replies)
Discussion started by: slayer0611
3 Replies

5. Shell Programming and Scripting

Need help using expect in shell scripts

hi all, i have this script that accepts passwords automatically and its working in one host only. my problem is how will i use it if i need it to run in more than one host/server let say by using "for loop statement" working : spawn bundle linux -r hostname checkpath... (2 Replies)
Discussion started by: linuxgeek
2 Replies

6. Shell Programming and Scripting

How to handle scripts that expect an input

Hi I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile. Bascically here is my script: #!/bin/bash csvdir="/var/local/dsx/csv/general" csvfile="$csvdir/$csvfile"... (3 Replies)
Discussion started by: ladyAnne
3 Replies

7. Shell Programming and Scripting

Difference between calling the sub scripts

What is the difference between calling the sub scripts of below two line. /home/scripts/devdb.sh . /home/scripts/devdb.sh sh /home/scripts/devdb.sh We are using the suse 2.0 version (4 Replies)
Discussion started by: kingganesh04
4 Replies

8. Solaris

difference in calling shell scripts

Hi I am getting some errors when i am running the shell script using the following syntax: >abc.sh but the same script works fine with the following syntax: >sh abc.sh wats the difference in both....please help thanks in advance. (6 Replies)
Discussion started by: arpit_narula
6 Replies

9. Shell Programming and Scripting

Calling expect scripts from other expect scripts

Hi, First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts. Below is my test where I am trying to call... (0 Replies)
Discussion started by: seva
0 Replies

10. UNIX for Dummies Questions & Answers

Difference in Shell Scripts

Hi, Is anyone can help me to find out the difference in Shell Scripts between HP and Sun. Thanks in advance, Vijay R (3 Replies)
Discussion started by: rv_kumar
3 Replies
Login or Register to Ask a Question