Because he grepdoesn’t know how to handle it |, be prepared for unpleasant shoots:
statement = """sh -c 'grep thing file | grep thing2 | tail -1'"""
This creates a shell on the other side and asks for its interpretation grep thing file | grep thing2 | tail -1 grep thing file | grep thing2 | tail -1 grep thing file | grep thing2 | tail -1. Single quotation marks are required because they sh -caccept only one argument.
Thus, the shell will create a channel for you by running all the commands. And you better be sure that the filename filedoes not contain spaces. If so, try it "file".
, . . sh -c script.sh.