Tec(h)tonic

Insights into building a solid I.T. foundation in the mid-size business world.

Using conditions to string together multiple *nix commands

I’m in the process of copying 30gb of data from one remote server to another and, only after I initiated the process did I think “Geez, it’d be nice to have a way for the system to notify me when the copy process completes so I don’t have to feel like I have to monitor it as it’s in-progress.”

Of course, TextBelt came to mind as an ideal way to do this and a quick Google search returned some great info about “bash operators/separators.”

  • | pipes the output of the left-side command as input for the right-side command
  • && executes the right-side command only if the left-side command completes successfully
  • || executes the right-side command only if the left-side command fails
  • ; executes the right-side command whether or not the left-side command completes successfully

So, in my current situation, I could’ve benefitted from something to the effect of:

scp -r <localDir> <userName>@<destinationSvr>:<destinationDir> && \
curl -X POST http://textbelt.com/text \
-d number=<phoneNumber> -d "message=scp complete."


Leave a Reply

Your email address will not be published. Required fields are marked *