I've created an Expect Script (.exp) to get the raw file in other server. Then, I also have .sh file to call my .exp. It's working well when I tried to run it in a usual way (./call_expect.sh). But when I scheduled it in CRONTAB, no raw data fetch and expect script didn't response. I am confused right now, I don't know if there's a problem in my header as they will conflict or if there's a problem in crontab.

SAMPLE EXPECT (directory.exp)


package require Expect
# set Variables
set USER {USER1234}
set NODE {test_server}
set DIR {/Daily/TESTING}
set PROMPT {$}
set COMMAND0 {ls -lrt Daily/TESTING | grep dr | grep -v tar | awk {'print $9'} | sort | grep ^2}
set quit_COMMAND {exit}

spawn ssh $USER@$NODE
expect {
send "$PASSWORD\r"

expect {
  "$PROMPT "
send "$COMMAND0\r"

expect {
  "$PROMPT "
send "exit\r"

SAMPLE .SH (call_expect.sh)


{locations . . . }

${BIN}/directory.exp | dos2unix | grep ^2 > ${CONFIG}/.list_dir.tmp

previous_directory=`cat ${CONFIG}/.list_dir.tmp | tail -2 | head -1`
latest_directory=`cat ${CONFIG}/.list_dir.tmp | tail -1  | head -1`

echo "`date` Previous Dir: ${previous_directory}   Latest Dir: ${latest_directory}"

I'm using Solaris 5.10.

1 Answer 1


I imagine you're getting errors from the awk command: single quotes appear to confuse awk (I'm testing this on a Mac, so your awk may behave differently)

$ seq 10 | awk "'print \$9'"
awk: cmd. line:1: 'print $9'
awk: cmd. line:1: ^ invalid char ''' in expression

awk demands braces for the action body.

Try this:

set COMMAND0 {ls ... | awk {{print $9}} | ...}

The outer braces are Tcl (and expect) quoting, the inner braces are for awk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .