Shell script ftp automatically upload files

Source: Internet
Author: User
Tags gz file

The following script compresses the local text file and uploads it to the FTP server.

Inside a little bit of logic, that is, the text file is uploaded date time. txt form, one day to write a log file, today's files do not upload, only upload

The old log file.

[C-sharp]View PlainCopy
  1. #/bin/sh
  2. suffix= ' Cat Suffix.ini '
  3. now= ' Date +%y%m%d '
  4. Curfile="./$now. txt"
  5. curgzfile="$curfile. tar.gz"
  6. Upload ()
  7. {
  8. ftp-n<<!
  9. Open 192.168.2.1
  10. User root 123456
  11. Binary
  12. mkdir Logservice
  13. CD Logservice
  14. LCD./
  15. Prompt
  16. Put "$"
  17. Ls
  18. Close
  19. Bye
  20. !
  21. }
  22. Updir="./uploaded"
  23. If [-D "$updir"]
  24. Then
  25. Echo "Updir exists"
  26. Else
  27. mkdir $updir
  28. Fi
  29. For file in $1./*.txt
  30. Do
  31. if [ "$file"! = "$curfile"]
  32. Then
  33. if [ "$file" ! = "./*.txt"]
  34. Then
  35. echo "$file"
  36. gzfile="$file. $suffix. tar.gz"
  37. if [-E "$gzfile"]
  38. Then
  39. echo "file $gzfile exists"
  40. Else
  41. Tar-cvzf " $gzfile" "$file"
  42. Echo "Create tar.gz file= $gzfile"
  43. Fi
  44. Upload $gzfile
  45. RM-FR $file
  46. MV "$gzfile" "./uploaded"
  47. Fi
  48. Fi
  49. Done

http://blog.csdn.net/langeldep/article/details/6166633

Shell script ftp automatically upload files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.