简体   繁体   中英

crontab doesn't run expect script

my expect fils is:

#!/bin/sh

/usr/bin/expect -c 'spawn /usr/bin/ssh root@x.x.x.x "/root/raw/test.sh";expect "password:"; send "pass\n"; interact'

my cron setting for this expect script is

*/2 * * * * bash /home/myuser/myfolder/test.sh

when I run the expect script by using command ./test.sh in terminal I run ok but doesn't run in crontab

i have to mention i also execute the test.sh by using chmod +x test.sh what should I do to run the expect script in cron?

2 problems:

  1. there's no executable named " /usr/bin/expect -f /home/myuser/myfolder/test.sh "

    • you don't put quotes around the command in a crontab entry.
  2. You want to invoke the script with the expect interpreter, but it's a shell script.

    • pick one of:
      1. */2 * * * * bash /home/myuser/myfolder/test.sh
      2. make it an expect script
        #./usr/bin/expect spawn ssh root@xxxx "/root/raw/test:sh" expect "password:" send "pass\n" interact

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM