Regular Linux shell script implementation sftp timed upload download file __linux

Source: Internet
Author: User

The reason to write this article, is because the Internet a lot of articles about the reprint, crontab command of the grammar is wrong, are directly turned, although very simple, but also will waste time Ah, especially for the first time to write students.

Turn to the point.

One: Timed tasks (most of the errors in the article is this part)

1. Executive Order: CRONTAB-E

2. Press I edit file, add command as follows:

* * * sh/home/uploadfile.sh

10 12 * * means to start the scheduled task 12:10 every day (refer to other information for specific time usage)

Sh/home/uploadfile.sh refers to executing scripts in the home directory uploadfile.sh

3. Press ESC to return to command line mode, then press: Wq Save and exit

The timed task was created successfully.

Many other articles are written in detail, but are the most critical 2nd part of the command error, write so much what is the use, basically write a * * * * */home/uploadfile.sh, did not write sh, so that the script will not execute AH.

So the complete syntax is divided into two parts, the first half is the time definition, the latter part is the command, how to execute the command at ordinary times, how to write this place

Two: sftp upload the downloaded shell script

The complete sftp upload script is as follows:

#!/bin/bash
#SFTP配置信息
#IP
ip=1.1.1.1
#端口
Port=22
#用户名
User=username
#密码
Password=password
#待上传文件根目录
Clientdir=/client/upload
#SFTP目录
Severdir=/server/upload
#待上传文件名
File=filename

Lftp-u ${user},${password} Sftp://${ip}:${port} <<eof
CD ${severdir}/
LCD ${clientdir}
Put ${file}
By
Eof

The complete sftp download script is as follows:

#!/bin/bash
#SFTP配置信息
#IP
ip=1.1.1.1
#端口
Port=22
#用户名
User=username
#密码
Password=password
#待接收下载文件根目录
Clientdir=/client/download
#服务器待下载目录
Severdir=/server/download
#待下载文件名
File=filename

Lftp-u ${user},${password} Sftp://${ip}:${port} <<eof
CD ${severdir}/
LCD ${clientdir}
Get ${file}
By
Eof

Other than that:

If prompted LFTP command is invalid, execute command: Yum install lftp-y, install

Hope to help students in need

Related Article

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.