четверг, 13 июня 2013 г.

cron + expect + interact

Be careful when you run your shell scripts from cron. cron doesn't have all terminal features. E.g. here's a script that does scp:
 spawn   scp file username@myserver:/home/user
  expect  "*assword: $"
  send    "mystrongpass\n"
  interact 
This example is widely spread. BUT. It won't work from cron. Look at the last directive 'interact'. It returns the process control to the user (there's no user) and redirects stdin and stdout to stdin/stdout of the current process. And it crashes. You should use 'expect' instead:
 spawn   scp file username@myserver:/home/user
  expect  "*assword: $"
  send    "mystrongpass\n"
  expect eof

Комментариев нет:

Отправить комментарий