LinuxQuestions.org
Visit Jeremy's Blog.
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 04-04-2018, 01:39 PM   #1
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 646

Rep: Reputation: 33
Unable to execute expect script from bash script AND from shell


Hello

I have a simple expect script :

Code:
[root@tst01 ~]# ls -lh /root/ | grep ht
-rwxr--r--  1 root root  337 apr  4 17:04 htdigestexpect.exp
Code:
[root@tst01 ~]# cat /root/htdigestexpect.exp 
#!/usr/bin/expect
set myuser [lindex $argv 0]
set mypass [lindex $argv 1]

spawn /usr/bin/htdigest -c /etc/httpd/.$myuser "blabla" $myuser

expect "New password:"
send "$mypass\r"

expect "Re-type new password:"
send "$mypass\r"
I want to execute this expect script from within a bash script :

Code:
#!/bin/bash
# $1 = user
# $2 = passwd
echo "htdigestexpect $1 $2 ..."
/usr/bin/expect ∕root/htdigestexpect.exp $1 $2
But this fails with output :
Quote:
htdigestexpect 770 mysecret ...
∕root/htdigestexpect.exp: no such file or directory
When I want to execute the expect script from shell, I also get :
Quote:
[root@tst01 ~]# /usr/bin/expect ∕root/htdigestexpect.exp 770 mysecret
couldn't read file "∕root/htdigestexpect.exp": no such file or directory
What is wrong here ??
 
Old 04-04-2018, 02:33 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,612

Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
Are you running as root?
With permissions set to 744, only root can run the expect script. *nixes often (usually?) return "no such file..." when attempting to execute a non-executable script.

Also, do you need to specify /usr/bin/expect on the command line or in the script? It's in the #!.

Edit: Looks like you are running as root from the command line. Hmmm.

Last edited by scasey; 04-04-2018 at 02:40 PM.
 
Old 04-04-2018, 02:43 PM   #3
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 646

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by scasey View Post
Are you running as root?
With permissions set to 744, only root can run the expect script. *nixes often (usually?) return "no such file..." when attempting to execute a non-executable script.
This info is given in my post. You can see that I am root and that the file is executable for user (root).
 
Old 04-04-2018, 02:56 PM   #4
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,612

Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
Quote:
Originally Posted by jonaskellens View Post
This info is given in my post. You can see that I am root and that the file is executable for user (root).
Yes. I could see that you ran the expect script from the command line as root...and hmmm'd about that, cause it is puzzling.
Couldn't see that you ran the shell script as root, tho.

I note in the man pages that the -f flag is required when using the #! syntax within the script, but apparently not on the command line.

I'll repeat the question: Might there be an issue in specifying expect on the command/script line and in the sh-bang? I don't know the answer...I'm just brainstorming...
 
Old 04-04-2018, 03:05 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,229

Rep: Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711
It looks like the file doesn't exist for expect

I would try to run it directly, adding -f at the end of first line of htdigestexpect.exp (like scasey says)
Code:
cd /root
./htdigestexpect.exp 770 mysecret

Last edited by keefaz; 04-04-2018 at 03:07 PM.
 
Old 04-04-2018, 03:25 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
There is a very special symbol here:
∕root/
 
Old 04-04-2018, 03:53 PM   #7
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,612

Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
NevemTeve: I saw that too, in the body of the shell script. The leading / looks strange, but just assumed that was from the posting here.
Besides, the OP tried to run the expect script, so even if that's a real typing glitch in the shell script, it wouldn't have affected that attempt.
 
Old 04-04-2018, 04:38 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,467

Rep: Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274Reputation: 2274
Quote:
[root@tst01 ~]# cat /root/htdigestexpect.exp
So the script appears to be in root's home directory.

Quote:
[root@tst01 ~]# /usr/bin/expect ∕root/htdigestexpect.exp 770 mysecret
couldn't read file "∕root/htdigestexpect.exp": no such file or directory
As far as I can tell /root/ is referencing root's home directory. What is confusing is that despite htdigestexpect.exp being in /root expect does not find it.

If your current working directory is ~ i.e. roots home then all the following commands are the same. As long as the script is readable it should execute.

/usr/bin/expect htdigestexpect.exp
/usr/bin/expect ./htdigestexpect.exp
/usr/bin/expect /home/root/htdigestexpect.exp

You would think the OP's problem would be fairly obvious...
 
Old 04-04-2018, 10:45 PM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
> the OP tried to run the expect script, so even if that's a real typing glitch in the shell script, it wouldn't have affected that attempt.

The same invalid character is present there, too.

Edit: it is U+2215

Last edited by NevemTeve; 04-05-2018 at 12:43 AM.
 
Old 04-05-2018, 03:42 AM   #10
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 646

Original Poster
Rep: Reputation: 33
Hello

the caveat was indeed in the strange character. Don't know how that got there.

My script works now !

FYI :

Executing the expect script commandline when in directory /root works :
Code:
[root@tst01 ~]# /usr/bin/expect htdigestexpect.exp myuser mypass
spawn /usr/bin/htdigest -c /etc/httpd/.myuser blabla myuser
Adding password for myuser in realm blabla.
New password: 
Re-type new password:
Executing the expect script commandline when NOT in directory /root works with -f flag :
Code:
[root@tst01 src]# /usr/bin/expect -f /root/htdigestexpect.exp myuser mypass
spawn /usr/bin/htdigest -c /etc/httpd/.myuser blabla myuser
Adding password for myuser in realm blabla.
New password: 
Re-type new password:
 
  


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
How to get the control back from expect script to a shell script? techyn Linux - Software 3 08-03-2012 08:13 AM
[SOLVED] Problem in exporting variable from bash script to expect script uk.engr Linux - Newbie 3 06-14-2012 01:57 AM
Issue in running commands in expect script from shell script yadvinder Programming 0 05-31-2012 04:07 AM
unable to execute shell scritp from php script kamlesh_kmr Programming 2 10-17-2011 12:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:35 PM.

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