samedi 17 janvier 2015

Redirection with nested commands


I am running a $command, in a instance of a screen, as a different user.

It's run by the equivalent of this command (more detailed at bottom):



su $USERNAME -c "screen -dmS $SCREENNAME $COMMAND"


and that works great. The problem is I want to redirect the output of $COMMAND to some logfile (e.g $LOGFILE).


Just adding > $LOGFILE to the end seems to read from screen instead of $COMMAND, so I am stumped as to what I should do. I've tried grouping it with parenthesis and braces, but that caused errors so I probably wasn't doing it correctly.


So how can I redirect the output of $COMMAND to $LOGFILE?




The code I am running is "equivalent" to this:



execute() {
su $USERNAME -c "$*"
}
COMMAND="$SOMEDIR/$SOMEPROG $SOMEARGS"
execute screen -dmS $SCREENNAME $COMMAND


Aucun commentaire:

Enregistrer un commentaire