Wednesday, 15 April 2015

python - Strange behavior redirecting to a file while using runuser -



python - Strange behavior redirecting to a file while using runuser -

i'm executing python file runuser , redirecting output file. command:

runuser -l "user" -c "/path/python-script.py parameter1 > /path/file.log &"

this run correctly python script creates empty log file. if run without redirect:

runuser -l "user" -c "/path/python-script.py parameter1 &"

runs correctly python script , create output python script flow screen. output python script done print output stdout.

i don't understand why output python script not dumped file. file permissions correct. log files created, not filled.

but, if remove "parameter1", error message reported python script correctly dumped log file:

runuser -l "user" -c "/path/python-script.py > /path/file.log &"

the error message done print too, don't understand why 1 message dumped , others not.

maybe runuser interprets "parameter1" command or something. but, parameter correctly passed script, can see ps:

/usr/bin/python /path/python-script.py connect

i've tried adding 2>&1 still don't work.

any thought ?

encountered similar problem in startup scripts, needed log output. in end came following:

usr=myuser prg=myprogrog wkd="/path/to/workdir" bin="/path/to/binary" arg="--my arguments" pid="/var/run/myapp/myprog.pid" su -l $usr -s /bin/bash -c "exec > >( logger -t $prg ) 2>&1 ; cd $wkd; { $bin $arg & }; echo \$! > $pid "

handy can have pid of process available. illustration writes syslog, if write file utilize cat:

log="/path/to/file.log" su -l $usr -s /bin/bash -c "exec > >( cat > $log ) 2>&1 ; cd $wkd; { $bin $arg & }; echo \$! > $pid "

it starts new shell , ties outputs command within exec.

python linux bash sh

No comments:

Post a Comment