LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-01-2010, 06:59 PM   #1
lazac
LQ Newbie
 
Registered: Mar 2010
Location: Budapest
Distribution: Debian
Posts: 8

Rep: Reputation: 0
Right order and grouping of sudo, nice, output redirection and "&" to start a program


Hi All,

I have an X11 GTK program, let's name it "foo".
I would like to start it from command line, either from a text console, or from an ssh log-in. I want to run foo with Administrator privileges and in higher priority, and I need redirect standard output and standard error. Standard errors must go to syslog, except "libglade Warning" messages and empty line messages. Standard output is redirected to a file.
I wrote a script, called "foo-start". The "foo" program must run continously, so the "foo-start" script should not wait for "foo"'s termination.
The scrip actually looks likelike this:


cd "FOO'S DIR"
(sudo nice --10 ./foo --display=localhost:0 &) 3>&1 1>foo-output.log 2>&3 | grep . | grep -v lobglade-WARNING | loggerr -p local7.err -t foo &



I use "&" so the script doesn't wait for foo's exit. I have put "nice" and "foo" into sudoers file.
This scipt works, but I am not sure, that it is the right and nice way. It may have side effects. For example, before I used a slighty different format:

(sudo nice --10 ./foo --display=localhost:0 ) 3>&1 1>foo-output.log 2>&3 | grep . | grep -v lobglade-WARNING | loggerr -p local7.err -t foo &

The difference only one missing "&", but this latter format doesn't started some times in a very slow computer.

Maybe this is better?!:

(sudo nice --10 (./foo --display=localhost:0) 3>&1 1>foo-output.log 2>&3 | grep . | grep -v lobglade-WARNING | loggerr -p local7.err -t foo) &

What is the right order and grouping of "sudo"/"nice", output redirection, and the "&" commands?
There is a better and more clear way to start "foo" with this conditions?
May I add a "nohup" command if I want to use "foo-start" from an ssh login?

Thanks in advance!
 
Old 03-02-2010, 04:12 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
sudo and redirections get very tricky, as the redirection of the sudo is whats done, so redirected to a non-root file, or piped to a non-root process. I'd very strongly suggest you break down your problem by creating a script to do everything you need to do within the root priveledge level, and then just run that script by sudo.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] When I type "sudo grub" it says "command not found" in Ubuntu 9.10 Live CD. msbstar Linux - Newbie 9 07-17-2017 01:27 PM
square brackets in output of "ps aux" not matching output of "ps -ejH" alirezan1 Linux - Newbie 14 07-14-2010 05:17 AM
running KDE4 apps using sudo: "Could not start ksmserver. Check your installation." ta0kira Slackware 2 12-28-2009 06:49 PM
Is there a "grouping of similar applications" function available in Gnome? mysteron Linux - Desktop 2 07-10-2009 01:45 AM
cannot "sudo apt-get uptate" or "sudo" anything! plz help mdguy21061 Linux - Newbie 7 04-14-2008 12:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration