Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am compiling something and depending on success (last line of output contains "success"= I want to scp the binary to the target. I'd prefer a piped oneliner. Is there a way to do this?

share|improve this question

4 Answers 4

You're not giving any information on what/how you are compiling. However, in most cases, the compiler will return a successful exit signal if it compiled correctly so you could just use the shell's features directly:

$ gcc -o foo.bin foo.c && echo YES || echo NO
YES
$ gcc -o foo.bin foo.txt && echo YES || echo NO
foo.txt: file not recognized: File truncated
collect2: error: ld returned 1 exit status
NO

So, in your case, you could probably simply run

$ complile_command && scp binary user@server:/remote/path     
share|improve this answer

Try this:

your command | tail -1 | grep -q 'success' && scp ...

Example:

% cuonglm at ~
% echo -e "sad\nsadsa\nsuccess" | tail -1 | grep -q 'success' && echo 'this command run'
this command run
share|improve this answer

One way:

cmd | awk 'END{exit!/success/}' && scp ...
share|improve this answer

You could, indeed, use a one-liner:

command | grep -q success && othercommand

This would execute othercommand if the command outputs something containing success.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.