bash - Suppress output of ftp in a shell script while executed in a cron job
问题描述
I'm running a backup shell script every night where i tar some data and then send it to a different server by sftp. As this is really important data i would like to get noticed by email if something goes wrong. Thats why i opted in to get notified if errors occur in the cron job (managed server).
This is how the sftp connection looks like:
sftp -i ~/.ssh/id_rsa server.com <<EOF
put $file
rm $file_old
EOF
Unfortunately right now i get a mail every time the script runs showing me the output of the sftp connection like this:
Connected to server.com.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
The script works and the files are transferred. So is there a way to hide the output of the sftp connection but yet show possible errors of the script. Any help is greatly appreciated!
解决方案
抑制这些进度条的示例方法是执行以下命令:
sftp -q -i ~/.ssh/id_rsa server.com <<EOF
put $file
rm $file_old
EOF
此命令将显示错误STDERR
推荐阅读
- python - Discord.py - 检测机器人何时离线
- javascript - 尝试使用可选链接 (?.) 时出现语法错误
- python - Python:Selenium Pagination 仅将第 1 页保存到列表中,但不保存第 2、3 页等
- .net-core - .NET Core/Standard 项目中的 IBMMQDotnetClient nuget 包行为
- javascript - svg 上的 Progressbar.js 边框半径
- java - 如何使用 Stream Api 从 Java 中的两个列表创建列表
- c# - 如何将数据传递到 ShellSection 的 ShellContent 以在 Xamarin.Forms Shell 应用程序上将同一页面用于不同目的?
- python - 如何确定哪个 py 文件(以及该 py 文件中的哪个类)调用了另一个 py 文件?
- intellij-idea - Intellij Idea 配置两个命令来部署 Angular 项目
- mysql - MySQL在过程中的if语句中选择