Expect script fails when running from cron but works when run manually
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a script in Linux that creates a file which once created it executes an Expect script that uploads the created file to an SFTP server. I have this running in cron and for whatever reason the upload always fails, however when I execute the script in the shell the upload is successful. I checked the logs and they're not really telling me where the process is going wrong.
Here's the shell script
#!/bin/bash
cd /home/mysql/paradata/repoupload || exit
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/gldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/vgldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
test -f gldetail.csv && ./SAFCO.sh
test -f vgldetail.csv && ./SAFCO.sh
if [ -f vgldetail.csv ]; then filename=vgldetail.csv; fi
if [ -f gldetail.csv ]; then filename=gldetail.csv; fi
if [ $filename == gldetail.csv ];
then
./uploadsafco.exp REPOEX > lastftplogsafco.txt
else
./uploadvafco.exp REPOEX > lastftplogvafco.txt
fi
Here's the expect script
#!/usr/bin/expect -f
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
set arg1 [lindex $argv 0]
set timeout 30
expect_after
timeout puts "Timeout"; exit 1
spawn sftp not@this
match_max 100000
expect "password: "
send -- "notapasswordr"
expect -exact "r
sftp> "
send -- "cd /usr/data/r1/EDr"
expect "sftp> "
send -- "progressr"
expect -exact "progressr
Progress meter disabledr
sftp> "
send -- "put REPOEXr"
expect "sftp> "
send -- "chmod 777 REPOEXr"
expect "sftp> "
send -- "byer"
expect eof
exit
linux shell cron expect
add a comment |Â
up vote
0
down vote
favorite
I have a script in Linux that creates a file which once created it executes an Expect script that uploads the created file to an SFTP server. I have this running in cron and for whatever reason the upload always fails, however when I execute the script in the shell the upload is successful. I checked the logs and they're not really telling me where the process is going wrong.
Here's the shell script
#!/bin/bash
cd /home/mysql/paradata/repoupload || exit
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/gldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/vgldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
test -f gldetail.csv && ./SAFCO.sh
test -f vgldetail.csv && ./SAFCO.sh
if [ -f vgldetail.csv ]; then filename=vgldetail.csv; fi
if [ -f gldetail.csv ]; then filename=gldetail.csv; fi
if [ $filename == gldetail.csv ];
then
./uploadsafco.exp REPOEX > lastftplogsafco.txt
else
./uploadvafco.exp REPOEX > lastftplogvafco.txt
fi
Here's the expect script
#!/usr/bin/expect -f
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
set arg1 [lindex $argv 0]
set timeout 30
expect_after
timeout puts "Timeout"; exit 1
spawn sftp not@this
match_max 100000
expect "password: "
send -- "notapasswordr"
expect -exact "r
sftp> "
send -- "cd /usr/data/r1/EDr"
expect "sftp> "
send -- "progressr"
expect -exact "progressr
Progress meter disabledr
sftp> "
send -- "put REPOEXr"
expect "sftp> "
send -- "chmod 777 REPOEXr"
expect "sftp> "
send -- "byer"
expect eof
exit
linux shell cron expect
2
You're not specifying the full path tosftp
-- is it available in cron's PATH for the user?
â glenn jackman
Jun 28 '17 at 15:11
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a script in Linux that creates a file which once created it executes an Expect script that uploads the created file to an SFTP server. I have this running in cron and for whatever reason the upload always fails, however when I execute the script in the shell the upload is successful. I checked the logs and they're not really telling me where the process is going wrong.
Here's the shell script
#!/bin/bash
cd /home/mysql/paradata/repoupload || exit
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/gldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/vgldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
test -f gldetail.csv && ./SAFCO.sh
test -f vgldetail.csv && ./SAFCO.sh
if [ -f vgldetail.csv ]; then filename=vgldetail.csv; fi
if [ -f gldetail.csv ]; then filename=gldetail.csv; fi
if [ $filename == gldetail.csv ];
then
./uploadsafco.exp REPOEX > lastftplogsafco.txt
else
./uploadvafco.exp REPOEX > lastftplogvafco.txt
fi
Here's the expect script
#!/usr/bin/expect -f
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
set arg1 [lindex $argv 0]
set timeout 30
expect_after
timeout puts "Timeout"; exit 1
spawn sftp not@this
match_max 100000
expect "password: "
send -- "notapasswordr"
expect -exact "r
sftp> "
send -- "cd /usr/data/r1/EDr"
expect "sftp> "
send -- "progressr"
expect -exact "progressr
Progress meter disabledr
sftp> "
send -- "put REPOEXr"
expect "sftp> "
send -- "chmod 777 REPOEXr"
expect "sftp> "
send -- "byer"
expect eof
exit
linux shell cron expect
I have a script in Linux that creates a file which once created it executes an Expect script that uploads the created file to an SFTP server. I have this running in cron and for whatever reason the upload always fails, however when I execute the script in the shell the upload is successful. I checked the logs and they're not really telling me where the process is going wrong.
Here's the shell script
#!/bin/bash
cd /home/mysql/paradata/repoupload || exit
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/gldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
mv /mnt/restrictedreports/Restricted/Corporate/Accounting/GL2013/vgldetail.csv /home/mysql/paradata/repoupload 2>/dev/null
test -f gldetail.csv && ./SAFCO.sh
test -f vgldetail.csv && ./SAFCO.sh
if [ -f vgldetail.csv ]; then filename=vgldetail.csv; fi
if [ -f gldetail.csv ]; then filename=gldetail.csv; fi
if [ $filename == gldetail.csv ];
then
./uploadsafco.exp REPOEX > lastftplogsafco.txt
else
./uploadvafco.exp REPOEX > lastftplogvafco.txt
fi
Here's the expect script
#!/usr/bin/expect -f
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
set arg1 [lindex $argv 0]
set timeout 30
expect_after
timeout puts "Timeout"; exit 1
spawn sftp not@this
match_max 100000
expect "password: "
send -- "notapasswordr"
expect -exact "r
sftp> "
send -- "cd /usr/data/r1/EDr"
expect "sftp> "
send -- "progressr"
expect -exact "progressr
Progress meter disabledr
sftp> "
send -- "put REPOEXr"
expect "sftp> "
send -- "chmod 777 REPOEXr"
expect "sftp> "
send -- "byer"
expect eof
exit
linux shell cron expect
linux shell cron expect
asked Jun 28 '17 at 13:20
Joseph Sortino
1225
1225
2
You're not specifying the full path tosftp
-- is it available in cron's PATH for the user?
â glenn jackman
Jun 28 '17 at 15:11
add a comment |Â
2
You're not specifying the full path tosftp
-- is it available in cron's PATH for the user?
â glenn jackman
Jun 28 '17 at 15:11
2
2
You're not specifying the full path to
sftp
-- is it available in cron's PATH for the user?â glenn jackman
Jun 28 '17 at 15:11
You're not specifying the full path to
sftp
-- is it available in cron's PATH for the user?â glenn jackman
Jun 28 '17 at 15:11
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
"Works manually, fails in cron" is almost always due to one of these:
- differences in environment variables:
PATH
and others; - different current working directory;
- lack of a TTY (probably not an issue with expect scripts);
- permissions (interactive testing with one user, cron job with another); or
- different shell: commands executed in within the cron command line itself use one shell, you may be interactively using another.
add a comment |Â
up vote
0
down vote
I have similar problem with my spawn telnet script. Script work fine until adding expect_after for handle timeout.
Try remove expect_after .. . It's work for me.
add a comment |Â
up vote
0
down vote
My question had just been marked as a copy of this one, but I still don't get the answer, why is the crontab line
30 14 10 10 * /usr/bin/expect -f /root/rutmain.sh
Not working when I try to run a expect script if it runs perfectly in shell, I get no error from the cron log, it just DON'T RUN.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
"Works manually, fails in cron" is almost always due to one of these:
- differences in environment variables:
PATH
and others; - different current working directory;
- lack of a TTY (probably not an issue with expect scripts);
- permissions (interactive testing with one user, cron job with another); or
- different shell: commands executed in within the cron command line itself use one shell, you may be interactively using another.
add a comment |Â
up vote
3
down vote
accepted
"Works manually, fails in cron" is almost always due to one of these:
- differences in environment variables:
PATH
and others; - different current working directory;
- lack of a TTY (probably not an issue with expect scripts);
- permissions (interactive testing with one user, cron job with another); or
- different shell: commands executed in within the cron command line itself use one shell, you may be interactively using another.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
"Works manually, fails in cron" is almost always due to one of these:
- differences in environment variables:
PATH
and others; - different current working directory;
- lack of a TTY (probably not an issue with expect scripts);
- permissions (interactive testing with one user, cron job with another); or
- different shell: commands executed in within the cron command line itself use one shell, you may be interactively using another.
"Works manually, fails in cron" is almost always due to one of these:
- differences in environment variables:
PATH
and others; - different current working directory;
- lack of a TTY (probably not an issue with expect scripts);
- permissions (interactive testing with one user, cron job with another); or
- different shell: commands executed in within the cron command line itself use one shell, you may be interactively using another.
answered Jul 24 '17 at 19:25
Kaz
4,45411431
4,45411431
add a comment |Â
add a comment |Â
up vote
0
down vote
I have similar problem with my spawn telnet script. Script work fine until adding expect_after for handle timeout.
Try remove expect_after .. . It's work for me.
add a comment |Â
up vote
0
down vote
I have similar problem with my spawn telnet script. Script work fine until adding expect_after for handle timeout.
Try remove expect_after .. . It's work for me.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have similar problem with my spawn telnet script. Script work fine until adding expect_after for handle timeout.
Try remove expect_after .. . It's work for me.
I have similar problem with my spawn telnet script. Script work fine until adding expect_after for handle timeout.
Try remove expect_after .. . It's work for me.
answered May 8 at 4:32
user289817
1
1
add a comment |Â
add a comment |Â
up vote
0
down vote
My question had just been marked as a copy of this one, but I still don't get the answer, why is the crontab line
30 14 10 10 * /usr/bin/expect -f /root/rutmain.sh
Not working when I try to run a expect script if it runs perfectly in shell, I get no error from the cron log, it just DON'T RUN.
add a comment |Â
up vote
0
down vote
My question had just been marked as a copy of this one, but I still don't get the answer, why is the crontab line
30 14 10 10 * /usr/bin/expect -f /root/rutmain.sh
Not working when I try to run a expect script if it runs perfectly in shell, I get no error from the cron log, it just DON'T RUN.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
My question had just been marked as a copy of this one, but I still don't get the answer, why is the crontab line
30 14 10 10 * /usr/bin/expect -f /root/rutmain.sh
Not working when I try to run a expect script if it runs perfectly in shell, I get no error from the cron log, it just DON'T RUN.
My question had just been marked as a copy of this one, but I still don't get the answer, why is the crontab line
30 14 10 10 * /usr/bin/expect -f /root/rutmain.sh
Not working when I try to run a expect script if it runs perfectly in shell, I get no error from the cron log, it just DON'T RUN.
answered 13 mins ago
Alejandro Enrique Garcia Navar
42
42
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f373922%2fexpect-script-fails-when-running-from-cron-but-works-when-run-manually%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You're not specifying the full path to
sftp
-- is it available in cron's PATH for the user?â glenn jackman
Jun 28 '17 at 15:11