简体   繁体   English

失败的 scp 传输会退出我的脚本吗?

[英]Will a failed scp transfer exit my script?

I have a shell script I am running which basically tars up log files and scp transfers the tar off the host to a remote host.我有一个正在运行的 shell 脚本,它基本上会压缩日志文件,然后 scp 将 tar 从主机传输到远程主机。

If the transfer is successful, on the next line of the script I want to purge my logs.如果传输成功,我想在脚本的下一行清除我的日志。 If the transfer fails i would not want to purge them.如果转移失败,我不想清除它们。

My question is, if the scp fails for whatever reason (poor GSM connectivity), will the script terminate at the fail of the scp, and naturally not run the purge on the next line, or do i need to add something in for protection if the scp fails to not purge the logs???我的问题是,如果 scp 由于某种原因失败(GSM 连接性差),脚本是否会在 scp 失败时终止,并且自然不会在下一行运行清除,或者我是否需要添加一些东西来保护如果scp 未能不清除日志??? Cheers.干杯。

scp -P $port /tmp/$filename user@host:/home/user/logs/
rm /home/user/logs/*

The idiomatic way to obtain this behavior is to write it as获得此行为的惯用方法是将其写为

scp ... || exit 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM