LinuxQuestions.org
Review your favorite Linux distribution.
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 06-13-2012, 02:19 AM   #1
uk.engr
Member
 
Registered: Apr 2012
Posts: 131

Rep: Reputation: Disabled
Problem in exporting variable from bash script to expect script


Assalam o Alaikum.

I can easily export variable from bash to bash script but not from bash to expect script. Here are my scripts:
[root@Zohaib 04]# vim initiate_operation.sh
#!/bin/bash
gxip= 192.168.1.121
mkdir -p /tmp/logs_auto
cp -n Email_words.txt /tmp/
export gxip
expect auto.sh

[root@Zohaib 04]# vim auto.sh
#!/usr/bin/expect -f
echo "$gxip"
spawn ssh root@$gxip
expect "*password*" {
send "123\r"
}

[root@Zohaib 04]# . ./initiate_operation.sh

can't read "gxip": no such variable
while executing
"echo "$gxip" "
(file "auto.sh" line 8)

Last edited by uk.engr; 06-13-2012 at 02:26 AM.
 
Old 06-13-2012, 09:57 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.

Code:
gxip= 192.168.1.121
     ^
There can't be any spaces around the equals sign when setting a shell variable.
 
Old 06-13-2012, 10:48 AM   #3
micropanther
LQ Newbie
 
Registered: Oct 2007
Location: Charlotte, NC
Distribution: Ubuntu 10.04, Davinci (MacOS/X)
Posts: 19

Rep: Reputation: 0
Wow, that took a lot of digging.

Your answer is found in the TCL/TK Wiki

I hate redirection as an answer so here is what I got to work
  1. There is a space after the "=" in your gxip= 192. ... statement. No spaces allowed unless you put quotes around the string.
  2. echo is not an expect command. Use puts instead.
  3. The variable you want to use is a global environment variable in the environment of the bash shell. Tcl/Tk gets all the global environment vars into an array named env. You get to env by referencing $::env(name_of_the_global_env_var). So in your case you need to puts $::env(gxip). Similar fixes for other lines where gxip is used.
 
Old 06-14-2012, 01:57 AM   #4
uk.engr
Member
 
Registered: Apr 2012
Posts: 131

Original Poster
Rep: Reputation: Disabled
Thanks you so much. it works thanks a lot............................................
 
  


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
Problem running an Expect script within a Bash script mbeipi Programming 8 03-15-2011 04:07 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
Bash Script Variable Problem jimmy512 Programming 5 05-11-2007 07:38 AM


All times are GMT -5. The time now is 12:27 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration