LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-11-2010, 08:42 AM   #1
dhirendrs
Member
 
Registered: Nov 2009
Posts: 32

Rep: Reputation: 15
Script is giving me error


Hi i create a file named “execute.sh” with below contents

#!/bin/bash

HOST="10.112.97.101"
USER="root"
PASS="xxxxxx"
CMD=$@

VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo "$VAR"

try to execute
./execute.sh "ls -l"

Giving error below
[root@PTPAADM tplinux]# ./execute.sh 'ls -l'
./execute.sh: line 15: expect: command not found
===============

Kindly do the needful...

Regards
Dhiren shah
 
Old 08-11-2010, 08:46 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by dhirendrs View Post
...
./execute.sh: line 15: expect: command not found
...
The error message is self-explanatory.
 
Old 08-11-2010, 08:53 AM   #3
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
A brief examination of the code tells me that you haven't got `expect` installed. Please verify that you do have `expect` on the machine, and if necessary, use the full path to `expect` if it is not in your $PATH.

I'm not sure why the error indicates the error is on line 15, but then, there are many cases I've seen where shell gives error line# that is not actually where the error is - but verify that you have `expect` first. If not, install it and try your script again.

NOTE: It may help us if you tell us what Linux OS you are using (since you posted from Windows, we cannot even guess) but I believe `expect` is normally installed on Linux in general.
 
Old 08-11-2010, 08:57 AM   #4
dhirendrs
Member
 
Registered: Nov 2009
Posts: 32

Original Poster
Rep: Reputation: 15
can u help me to resolve it

I am not getting error understanding

Quote:
Originally Posted by Sergei Steshenko View Post
The error message is self-explanatory.
 
Old 08-11-2010, 08:59 AM   #5
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Code:
./execute.sh: line 15: expect: command not found
Please verify that `expect` is installed on the machine.
 
Old 08-11-2010, 10:18 AM   #6
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,456

Rep: Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538
Quote:
Originally Posted by dhirendrs View Post
I am not getting error understanding
Ok, maybe this will "do the needful"
  • Your script clearly says it can't find the "expect" command.
  • Since it can't find it, that means it's probably not installed
  • INSTALL IT
 
Old 08-11-2010, 11:01 AM   #7
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 621

Rep: Reputation: 136Reputation: 136
Arre dhiren,

(1) expect is the name of a package that has to be installed before testing the syntax of your script.

(2) If you tell which distro (distribution) you are using, we may be able to tell you how to check if expect is installed or not and if not installed, how to download and install under linux.

(3) Are you getting internet from linux?

End
 
Old 08-11-2010, 11:30 PM   #8
dhirendrs
Member
 
Registered: Nov 2009
Posts: 32

Original Poster
Rep: Reputation: 15
Thanks all , need help .

Hi

I am using centos 5.2 ( Final)

how to check it is install or not if it is not from where i will get
Download for my Centos 5.2 ( Final).

Regards
Dhiren sha


Quote:
Originally Posted by AnanthaP View Post
Arre dhiren,

(1) expect is the name of a package that has to be installed before testing the syntax of your script.

(2) If you tell which distro (distribution) you are using, we may be able to tell you how to check if expect is installed or not and if not installed, how to download and install under linux.

(3) Are you getting internet from linux?

End
 
Old 08-12-2010, 06:42 AM   #9
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
You could see if it were installed just by running the `expect` command from your shell, or running `which expect`, or by asking your package installer, which I believe is called "yum". Since I don't use or know about "yum", and I don't use CentOS, you will have to await help on that from a yum/CentOS user; but the yum manpage should have a good explanation of possible commands. To read the man page:
Code:
shell$ man yum

Here's what I'd do meanwhile, to see if `expect` is installed:

Code:
# let's ask where expect is located:
shell$ which expect
/usr/bin/expect    << tells me that `expect` is in /usr/bin/

# Let's try starting expect command-line:
root@reactor: expect
expect1.1>     << Look~ the expect1.1 command interpreter has started, so I have `expect`. (Type "exit" to quit)

Here's a yum command to install `expect` - but as I said, I haven't a clue if this is the right command, so either read the instructions, or await further help, or try this at your own risk:
Code:
# For RHEL/OEL/Centos version 5:

shell$ sudo yum install expect expectk
I got that command from a post half-way down this page here, which I found using Google:
http://forums.oracle.com/forums/thre...sageID=4479232


Finally, here's a page from the CentOS wiki/main site, which you can go to and select an information topic about CentOS. The first subject on the list is dealing with CentOS repositories - repositories are where you get your software packages from:
http://wiki.centos.org/AdditionalResources
 
  


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
why is my shell script giving me - syntax error near unexpected token 'enterInfo() chisunum Linux - Newbie 3 10-23-2009 03:37 PM
rsh <hostname> <script path> giving permission denied error shad.ithbti Linux - Newbie 5 08-31-2009 07:55 AM
giving the answer from the script basak Linux - Software 3 08-14-2006 09:36 AM
Burning a .dmg file Perl Script giving zlib error zwyrbla Linux - General 1 08-19-2005 04:02 PM


All times are GMT -5. The time now is 06:44 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