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
- #/bin/sh
- suffix= ' Cat Suffix.ini '
- now= ' Date +%y%m%d '
- Curfile="./$now. txt"
- curgzfile="$curfile. tar.gz"
- Upload ()
- {
- ftp-n<<!
- Open 192.168.2.1
- User root 123456
- Binary
- mkdir Logservice
- CD Logservice
- LCD./
- Prompt
- Put "$"
- Ls
- Close
- Bye
- !
- }
- Updir="./uploaded"
- If [-D "$updir"]
- Then
- Echo "Updir exists"
- Else
- mkdir $updir
- Fi
- For file in $1./*.txt
- Do
- if [ "$file"! = "$curfile"]
- Then
- if [ "$file" ! = "./*.txt"]
- Then
- echo "$file"
- gzfile="$file. $suffix. tar.gz"
- if [-E "$gzfile"]
- Then
- echo "file $gzfile exists"
- Else
- Tar-cvzf " $gzfile" "$file"
- Echo "Create tar.gz file= $gzfile"
- Fi
- Upload $gzfile
- RM-FR $file
- MV "$gzfile" "./uploaded"
- Fi
- Fi
- Done
http://blog.csdn.net/langeldep/article/details/6166633
Shell script ftp automatically upload files