Скрипт синхронизации каталогов при помощи rsync
Рубрика: bash скрипты
Копирования на ftp-сервер через bash
На просторах интернета найден мною и опробован скрипт, который закачивает файлы на ftp-сервер.
#!/bin/bash HOST=ftp.server.com #This is the FTP servers host or IP address. USER=ftpuser #This is the FTP user that has access to the server. PASS=password #This is the password for the FTP user. # Call 1. Uses the ftp command with the -inv switches. #-i turns off interactive prompting. #-n Restrains FTP from attempting the auto-login feature. #-v enables verbose and progress. ftp -inv $HOST << EOF # Call 2. Here the login credentials are supplied by calling the variables. user $USER $PASS # Call 3. Here you will change to the directory where you want to put or get cd /path/to/file # Call4. Here you will tell FTP to put or get the file. put test.txt # End FTP Connection bye EOF
Скрипт протестирован и полностью работоспособен.
На забывать дать скрипту разрешение на выполнение:
chmod +x ftpscript.sh
Источник — http://serverfault.com/questions/279176/ftp-uploading-in-bash-script
Удаление старых бэкапов
Скрипт оставляет определённое кол-во свежих файлов (каталогов, архивов), а остальное удаляет.
#!/bin/bash #целевой каталог target_dir= #кол-во оставляемых файлов limit= n=1 for i in `ls $target_dir -t` do if [ $n -gt $limit ] then rm -Rvf $target_dir/$i fi n=$(($n+1)) done