tags:

views:

41

answers:

3

Okay, I currently use an eggdrop IRC bot on my server. I want to make a bash script to start it up as well as a few other scripts at the same time. All that's left is to make it start, but it won't run as root.

However, I also need to be in the current directory of the file to run it, or it displays an error.

For example: /home/eggdrop/eggdropbot/eggdrop will display an error, so to run it I need to cd /home/eggdrop/eggdropbot and then ./eggdrop

So I can't just use "sudo -u eggdrop /home/eggdrop/eggdropbot/eggdrop" and as you probably know, sudo won't cd, either, since that would be pointless.

Any suggestions?

+2  A: 

Why not just cd first and then sudo -u ./eggdrop .?

Josh K
Because somehow I'm an idiot and didn't think of that. One second let me try it.
Rob
Ugh I'm an idiot, worked like a charm. I actually thought of that earlier and I guess I forgot about it. Was trying too hard to make it a bit more simple, I guess. Only managed to make it more difficult. Thanks
Rob
No problems. :)
Josh K
+1  A: 

What about doing the cd, and, only then, launch the command with sudo ?

I suppose something like this should do the trick :

cd /home/eggdrop/eggdropbot && sudo -u eggdrop ./eggdrop
Pascal MARTIN
A: 

You can cd to the directory as the root user and then use sudo -u to invoke the program from the working directory.

rmeador