Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


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

Rep: Reputation: 544Reputation: 544Reputation: 544Reputation: 544Reputation: 544Reputation: 544
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:

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

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, 03:03 PM   #2
Registered: Jan 2004
Location: Los Angeles
Distribution: Slack64 14.1
Posts: 568

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

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

Original Poster
Rep: Reputation: 544Reputation: 544Reputation: 544Reputation: 544Reputation: 544Reputation: 544
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, 04:31 PM   #4
Slackware Contributor
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 229Reputation: 229Reputation: 229
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, 06:08 PM   #5
Senior Member
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

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


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

All times are GMT -5. The time now is 04:45 PM.

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