Advertisement
Guest User

Untitled

a guest
Aug 14th, 2023
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.54 KB | Source Code | 0 0
  1. #!/bin/bash
  2. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  3. cd "$SCRIPT_DIR"
  4.  
  5. if [[ ! -f "settings.conf" ]]; then
  6.     echo 'Welcome to JaneAlly! Please enter your OfficeAlly SFTP login details to begin.'
  7.     read -p 'OfficeAlly SFTP address: ' host
  8.     read -p 'OfficeAlly SFTP username: ' user
  9.     read -sp 'OfficeAlly SFTP password: ' pass
  10.     echo -en "host=\"$host\"\nport=\"22\"\nuser=\"$user\"\npass=\"$pass\"" > settings.conf
  11.     echo
  12. fi
  13.  
  14. . settings.conf
  15. if [[ -f "history.log" ]]; then
  16.     mv history.log history.old
  17. fi
  18.  
  19. expect <(cat <<EOD
  20. set timeout 20
  21.  
  22. # Connect to SFTP server
  23. spawn sftp -P $port -oUser=$user -p $host
  24. expect assword:
  25. send "$pass\r"
  26. expect sftp>
  27.  
  28. # Upload edi files to inbound folder
  29. send "put EDI/*.edi inbound\r"
  30. expect sftp>
  31.  
  32. # Get list of remittance files
  33. log_file -noappend history.log
  34. send "ls outbound/*ERA_STATUS*.zip -1t\r"
  35. expect "sftp>"
  36. log_file
  37. send "!sed -i '' 1d ./history.log\r"
  38. expect "sftp>"
  39. send "!sed -i '' '/sftp>/d' ./history.log\r"
  40. expect "sftp>"
  41. send "exit\r"
  42. expect eof
  43. EOD
  44. )
  45.  
  46. newfiles=$(comm -13 history.old history.log | tr -d "\t\n\r" | tr -s ' ')
  47. newfiles=(${newfiles// / })
  48. echo "${#newfiles[@]}"
  49.  
  50. expect <(cat <<EOD
  51. set timeout 20
  52.  
  53. # Connect to SFTP server
  54. spawn sftp -P $port -oUser=$user -p $host
  55. expect assword:
  56. send "$pass\r"
  57. expect sftp>
  58. foreach file $newfiles {
  59.     send "get ${newfiles} ERA\r"
  60.     expect "sftp>"
  61. }
  62.  
  63. send "exit\r"
  64. expect eof
  65. EOD
  66. )
  67.  
  68. echo 'ERA download complete, cleaning up files...'
  69. rm -f EDI/*.edi
  70. echo 'Clean up complete.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement