简体   繁体   中英

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.

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??? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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