bashantshsu

Run a command with su -c and exit when done


I'm trying to run a command using another user using the following:

sudo su - myuser -c "/my/command.sh -Dparam=lorem | sed '/^BUILD SUCCESSFUL$/ q'";

The sh files calls an ant script. I need this to end when the BUILD SUCCESSFUL appears on the file. However, if I run this within myuser, it works. If I run it through another user, and using su -c, it doesn't exit at the end, and I need to press CTRL+C.

How do I exit at the end?

/my/command.sh contains the following:

nohup something.sh > /opt/lastrun.log &
tail -n 0 -f /opt/lastrun.log

Solution

  • I solved by turning the pipe sed into

    { sed '/^BUILD SUCCESSFUL$/ q'; pkill -PIPE -xg0 tail; }