How to run a program for a specific user in ubuntu,,,,,

Asked by ullas

i have a daemon program that runs in both admin user and guest user,

I want to modify the script so that it will only run for a specific user..

How can it be done...

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu ddclient Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

run it using su, this will allow you to run a command as another user.

andy@D420:~$whoami
andy
andy@D420:~$su leanne -c whoami
[sudo] password for leanne:
leanne

You can also run the su command with sudo and you can use your own password

Revision history for this message
ullas (ullas-unnikrishnan) said :
#2

Ok that was the command i was looking for..

But can u tell me how i will use the command.

Actually my daemon program is ddclient updater .So at the start of this i want it to check for user and then for the specific user run it... How will do it..

if whoami="guest"
  then continue
else
  quit..

Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#3

You can use;

#!/bin/bash
if [ "$(whoami)" == "guest" ]; then
#continue command here
fi

Any other user than guest will make the command not run (The # character under 'if' means it is a comment, replace it with what you want.

e.g.

#!/bin/bash
if [ "$(whoami)" == "guest" ]; then
  echo "You are the guest account"
fi

Etc. Remember to chmod +x the script so it can be executed, or you will get access denied.

Revision history for this message
ullas (ullas-unnikrishnan) said :
#4

Hey i will try this and let u know.
I think this will solve the problem.

What do u meant by chmod + the script .. I am novice user so dont know about it??

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

The text file you make is just that, a text file. If you want it to be a script you need to mark it as executable, that's what chmod +x does