LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 06-15-2008, 02:11 PM   #1
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534
Running A Single Command In A Script As A Different User


I'm running a script as root. Within that script I want to run a single command as the person logged in, which usually is not root. The single command slaps a conky display item on the user's desktop.

The problem is the conky braces and parentheses that need to be passed as actual characters and not shell symbols. I've unsuccessfully tried various methods of backslashes and the like to properly pass the command.

In the script I want to run:

Code:
su - `logname` -c conky -t '${color green}'$DRIVEMODEL'('${BACKUPDISK:5:3}') Temp:${color white} ${hddtemp '$BACKUPDISK'}' -x 280 -y 297 &>/dev/null
Where:
DRIVEMODEL=WDK7500AAKS
BACKUPDISK=/dev/sdb


When I try running the complete command I receive "bad substitution" error messages. The error message makes sense to me and I understand what is happening. Yet I am struggling with the syntax I need to run the complete command.

By itself the conky command runs fine from the command line or from within my script, but not in conjunction with the su command.

Of course, I cannot split the su and conky command because the moment I su as a different user, the script terminates. I need to run both commands together.

The challenge is the su command requires the text following the -c option be enclosed in single or double quotation marks, otherwise the su command stops reading the text after the first space. When I enclose the entire conky portion in double quotation marks, I receive the shell error messages.

I appreciate help. As always, thanks.
 
Old 06-15-2008, 04:03 PM   #2
MQMan
Member
 
Registered: Jan 2004
Location: Los Angeles
Distribution: Slack64 13.37
Posts: 536

Rep: Reputation: 36
Try using sudo instead of su. I had some strange issues trying to use su inside a script.

Cheers.
 
Old 06-16-2008, 01:15 PM   #3
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534
Thanks for the idea. Originally I had tried sudo but that did not succeed, for whatever reasons my mind currently cannot remember.

While using the sudo command might provide a better long-term solution, which I'll again investigate, I still would appreciate help from anybody with learning how to properly format the su command in my script to pass the conky directive. Thanks again.
 
Old 06-16-2008, 05:31 PM   #4
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 227Reputation: 227Reputation: 227
Not having conky to test with...

Can you enclose the command in the usual "" and just backslash escape the single quotes?

Not sure if it will work but worth a try.
 
Old 06-16-2008, 07:08 PM   #5
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
If nothing else you can put that long conky command in a small script that you simply execute with su.
 
  


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
single command in shell script not working farkus888 Programming 5 04-01-2008 02:31 PM
shell script/command for converting columns/table onto a single line skuz_ball Programming 9 11-30-2007 04:02 AM
Running a script with another user brazilian_user Linux - General 8 10-18-2006 10:24 PM
MySQL - command - create user/single database dmedici Linux - Software 3 06-21-2004 04:17 PM
Running a script at user login? brucebearau Debian 1 01-19-2004 05:28 AM


All times are GMT -5. The time now is 04:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration