Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
- cd "$SCRIPT_DIR"
- if [[ ! -f "settings.conf" ]]; then
- echo 'Welcome to JaneAlly! Please enter your OfficeAlly SFTP login details to begin.'
- read -p 'OfficeAlly SFTP address: ' host
- read -p 'OfficeAlly SFTP username: ' user
- read -sp 'OfficeAlly SFTP password: ' pass
- echo -en "host=\"$host\"\nport=\"22\"\nuser=\"$user\"\npass=\"$pass\"" > settings.conf
- echo
- fi
- . settings.conf
- if [[ -f "history.log" ]]; then
- mv history.log history.old
- fi
- expect <(cat <<EOD
- set timeout 20
- # Connect to SFTP server
- spawn sftp -P $port -oUser=$user -p $host
- expect assword:
- send "$pass\r"
- expect sftp>
- # Upload edi files to inbound folder
- send "put EDI/*.edi inbound\r"
- expect sftp>
- # Get list of remittance files
- log_file -noappend history.log
- send "ls outbound/*ERA_STATUS*.zip -1t\r"
- expect "sftp>"
- log_file
- send "!sed -i '' 1d ./history.log\r"
- expect "sftp>"
- send "!sed -i '' '/sftp>/d' ./history.log\r"
- expect "sftp>"
- send "exit\r"
- expect eof
- EOD
- )
- newfiles=$(comm -13 history.old history.log | tr -d "\t\n\r" | tr -s ' ')
- newfiles=(${newfiles// / })
- echo "${#newfiles[@]}"
- expect <(cat <<EOD
- set timeout 20
- # Connect to SFTP server
- spawn sftp -P $port -oUser=$user -p $host
- expect assword:
- send "$pass\r"
- expect sftp>
- foreach file $newfiles {
- send "get ${newfiles} ERA\r"
- expect "sftp>"
- }
- send "exit\r"
- expect eof
- EOD
- )
- echo 'ERA download complete, cleaning up files...'
- rm -f EDI/*.edi
- echo 'Clean up complete.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement