Monday, October 21, 2013

Autosys/Cron job to download ftp files with expect

Expect is a program that "talks" to other interactive programs according to a script. Expect reads cmdfile for a list of commands to execute.
following commands are available under expect package.

  • spawn - starts a process
  • send  - sends to a process
  • expect - waits for output from a process
  • interact - lets you interact with a process


Example auto download scrit using expect which connects with other ftp server and download the define files.


#!/usr/local/bin/expect spawn /usr/local/bin/sftp user_name@ftp.server.com expect "Password:" send "password\r" expect "sftp>" send "cd /documents/downloadfiles\r" expect "sftp>" send "mget O_UEN*.XML \r " expect "sftp>" send "mget O_UL*.XML \r " expect "sftp>" send "mget O_UF*.XML \r " expect "sftp>" send "mget O_AUDIT.XML \r " expect "sftp>" send "bye\r"


The first line is the command interpreter.Then its Wait for the input and send the output. If we don't know the output of the next line , means if we don't know
the expect line then we can use "autoexpect" package instead of "expect" package.

No comments:

Post a Comment