Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-16-2003, 11:50 AM   #1
LQ Newbie
Registered: Sep 2003
Location: Salt Lake City
Distribution: Fedora
Posts: 9

Rep: Reputation: 0
Cool expect scripting

I used autoexpect to create an expect script. I works when I execute it manually. I put it in cron.daily and expected it to fire off at 4:00 AM. It didn't. I assume I missed something in cron, because the script works when fired off manually.
Old 12-16-2003, 12:30 PM   #2
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
Before you execute it, do you load the user environment?

Called Script


Old 12-16-2003, 02:56 PM   #3
LQ Newbie
Registered: Sep 2003
Location: Salt Lake City
Distribution: Fedora
Posts: 9

Original Poster
Rep: Reputation: 0
Here's the script with the password ***** out:

#!/usr/bin/expect -f
# This Expect script was generated by autoexpect on Mon Dec 15 16:48:17 2003
# Expect and autoexpect were both written by Don Libes, NIST.
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg

# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
# Read the man page for more info.
# -Don

set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "]0;dhanks@kronos:/etc/cron.daily\[root@kronos cron.daily\]# "
send -- "telnet atherton-2651-01\r"
expect -exact "telnet atherton-2651-01\r
Connected to (\r\r
Escape character is '^\]'.\r\r
User Access Verification\r
Password: "
send -- "********\r"
expect -exact "\r
send -- "en\r"
expect -exact "en\r
Password: "
send -- "********\r"
expect -exact "\r
send -- "rel\r"
expect -exact "rel\r
Proceed with reload? \[confirm\]"
send -- "\r"
expect -exact "\r
Connection closed by foreign host.\r\r
]0;dhanks@kronos:/etc/cron.daily\[root@kronos cron.daily\]# "
send -- "exit\r"
expect eof

I'm thinking I can pare down the lines that include the bash promt to just a #. Perhaps when cron runs it doesn't see exactly the same path.


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
Expect how to? e-freak Programming 2 09-24-2005 05:49 AM
[Expect scripting] send problem ldp Programming 1 01-24-2005 03:39 PM
help with expect neyoung Programming 3 02-09-2004 10:41 PM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 04:34 PM
expect scripting syntax problems...(catch, echo,....) wedgeworth Linux - Software 2 10-02-2003 10:24 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration