Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to pass variables in Expect command? Post 302541768 by mailkarthik on Monday 25th of July 2011 03:45:59 PM
Old 07-25-2011
How to pass variables in Expect command?

Hi All,
I need to frame a unix script to logon to a unix box. The credentials needs to be obtained from a property file on the same location.

I am trying to use 'expect' and 'spawn' command to meet this req.

When I am passing values, these commands are working fine. but when I am trying to pass variable, it is failing... Smilie

Command used :
Code:
expect -c 'spawn ssh $UNIX_USER@$UNIX_BOX ; expect password ; send "($UNIX_PWD)\n" ; interact'

Error Message:
Code:
can't read "UNIX_USER": no such variable
    while executing
"spawn ssh $UNIX_USER@$UNIX_BOX "

Appreciate your help.

-kt

Last edited by radoulov; 07-26-2011 at 03:43 PM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass CSH variables up to the parent?

Hi .. I have a dynamic script called from a programming language called Powerhouse (4GL). The module, called QUIZ, allows the user to call shell commands from within it... i.e. !rm -f mipss156t2cmd1.bat mipss156t2tmp1.txt !printf '#!/bin/csh\n' > mipss156t2cmd1.bat !printf 'setenv... (0 Replies)
Discussion started by: ElCaito
0 Replies

2. Shell Programming and Scripting

How to pass variables to FUNCTION ?

Hi... Actually, I want to pass a few variables to the function and print it. But, its looks like not working. Could some body help me how could i do that ?... below is my program... #!/usr/bin/ksh usage() { echo "Usage: $0 -n -a -s -w -d" exit } rename() { echo "rename $1 $2"... (5 Replies)
Discussion started by: bh_hensem
5 Replies

3. Shell Programming and Scripting

pass variables from one script to another

HI all I am calling a script "b" from script "a". In script "a", i connect to database and get month and year. I have to pass these same values to script b. How can i do that. How can i pass parameters from one script to another (3 Replies)
Discussion started by: vasuarjula
3 Replies

4. Shell Programming and Scripting

SED command help: Can we pass predefined variables in place of regex

Hi All, I have a doubt. Can we assign a regular expression for pattern searching to a variable in a script and then use that variable in place of a regular expression in sed command.I tried but got some syntax error!!Is it not possible.Because my requirement is that i have a generic script to get... (8 Replies)
Discussion started by: usha rao
8 Replies

5. Shell Programming and Scripting

Sending test pass to a folder in expect

still new to this expect useing bach shell to cammand expect script i tink i have that right! i want to have the test im running upon every complted cycle copyed to a folder. cant seem to get it to work. Ive tryed log_file -a $globallogdir/deveoper.log proc dbglog {notsure what... (0 Replies)
Discussion started by: melvin
0 Replies

6. Shell Programming and Scripting

Pass subshell through expect and SSH

Hi folks, What I want to do is to check if there is an instance of running vlc on a remote server, then kill it, and start it again. The code I came up with is: #!/bin/bash expectFcn() { expect -c " set timeout -1 spawn ssh \"$1@$2\" \"$4\" match_max 100000 expect { -re... (2 Replies)
Discussion started by: dukevn
2 Replies

7. Shell Programming and Scripting

How to pass variable with spaces from shell to expect?

I need call expect script from shell script and pass values some of which could contain space. How to make expect to treat such values as one variable? (1 Reply)
Discussion started by: urello
1 Replies

8. Shell Programming and Scripting

Expect and variables

I'm trying to make an expect function that will pass through a variable. /usr/bin/expect<<EOD spawn su - expect "Password: " send "$psswd\r" expect "#" send "/etc/init.d/network restart >>$log\r" expect "#" send "exit\r" EOD The $log passes through but my $psswd fails I know... (1 Reply)
Discussion started by: Lotheovian
1 Replies

9. Shell Programming and Scripting

How to pass variables between scripts?

Hello, I have two bash scripts like the following: script 1: #!/bin/bash var=WORLD bash path/to/second/script/script2.bash script 2: #!/bin/bash echo "HELLO $var" I expected the output to be "HELLO WORLD" but instead, I get "HELLO". I understand that when I envoke another bash... (2 Replies)
Discussion started by: jl487
2 Replies

10. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies
POSIX_SPAWNATTR_INIT(3) 				   BSD Library Functions Manual 				   POSIX_SPAWNATTR_INIT(3)

NAME
posix_spawnattr_init, posix_spawnattr_destroy -- initialize and destroy spawn attributes object LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <spawn.h> int posix_spawnattr_init(posix_spawnattr_t * attr); int posix_spawnattr_destroy(posix_spawnattr_t * attr); DESCRIPTION
The posix_spawnattr_init() function initializes a spawn attributes object attr with the default value for all of the individual attributes used by the implementation. Initializing an already initialized spawn attributes object may cause memory to be leaked. The posix_spawnattr_destroy() function destroys a spawn attributes object. A destroyed attr attributes object can be reinitialized using posix_spawnattr_init(). The object should not be used after it has been destroyed. A spawn attributes object is of type posix_spawnattr_t (defined in <spawn.h>) and is used to specify the inheritance of process attributes across a spawn operation. The resulting spawn attributes object (possibly modified by setting individual attribute values), is used to modify the behavior of posix_spawn() or posix_spawnp(). After a spawn attributes object has been used to spawn a process by a call to a posix_spawn() or posix_spawnp(), any function affecting the attributes object (including destruction) will not affect any process that has been spawned in this way. RETURN VALUES
Upon successful completion, posix_spawnattr_init() and posix_spawnattr_destroy() return zero; otherwise, an error number is returned to indi- cate the error. ERRORS
The posix_spawnattr_init() function will fail if: [ENOMEM] Insufficient memory exists to initialize the spawn file actions object. SEE ALSO
posix_spawn(3), posix_spawnp(3) STANDARDS
The posix_spawnattr_init() and posix_spawnattr_destroy() functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The posix_spawnattr_init() and posix_spawnattr_destroy() functions first appeared in FreeBSD 8.0 and imported for NetBSD 6. AUTHORS
Ed Schouten <ed@FreeBSD.org> BSD
December 20, 2011 BSD
All times are GMT -4. The time now is 01:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy