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