LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 05-01-2014, 09:07 AM   #1
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Rep: Reputation: 1
/etc/rc.local questions: running script with user privileges


I am looking to run a script (namely, one that starts the Synergy Client) at startup BEFORE login (because plugging in a keyboard whenever I reboot to login is getting annoying). I am fairly sure that I know the command to input into /etc/rc.local, however I believe this runs the script at root. This is a problem. If this becomes a process owned by root, the user (me) can not stop and then restart the client in case something goes wrong such as an interruption in the connection. How do I run this task as me and not root on startup?
 
Old 05-01-2014, 11:39 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

You can use su for that:
Code:
su - username -c /path/to/script
Cheers
 
2 members found this post helpful.
Old 05-01-2014, 11:51 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Going off the manual page:

Quote:
su [OPTION]... [-] [USER [ARG]...]
Code:
su -c '/yourscript.sh' - username
 
Old 05-01-2014, 12:06 PM   #4
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by bathory View Post
Hi,

You can use su for that:
Code:
su - username -c /path/to/script
Cheers
That is so simple. Why didn't think of that?

Thank you for your help!
 
Old 05-01-2014, 12:07 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i like to use crontab (@reboot) for stuff like this.
 
Old 05-01-2014, 02:37 PM   #6
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Original Poster
Rep: Reputation: 1
ok, I spoke too soon

I have tried all three of the suggestions in this thread. Synergy still does not start when I boot. I need it to start at boot BEFORE the user login as there is no keyboard and mouse attached to this pc. Both keyboard and mouse commands are handled though Synergy.

This is the script I am using:
Code:
synergyc --name WorkTop 123.45.6.789
And here is the line in /etc/rc.local:
Code:
su -c /home/user1/bash_scripts/start_synergy.bash - user1
When I run 'su -c /home/user1/bash_scripts/start_synergy.bash - user1' from the command line (as root) it works like a charm.

What am I doing wrong? This command depends upon a working network connection. Does this run before the network card is up and running?

##EDIT## The network thing should not be a problem. I have another line in rc.local that uses google-drive-ocamlfuse to connect to my Google Drive folder and it runs without a hitch. So there is SOMETHING about the synergyc command.

Last edited by thealmightyos; 05-01-2014 at 02:43 PM. Reason: new info
 
Old 05-01-2014, 02:44 PM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
probably... does cron email you an error (mail) ?

you can try putting something like sleep 60 before the command ?
 
Old 05-02-2014, 12:58 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
When I run 'su -c /home/user1/bash_scripts/start_synergy.bash - user1' from the command line (as root) it works like a charm.

What am I doing wrong? This command depends upon a working network connection. Does this run before the network card is up and running?
rc.local is executed as the last thing in the boot process, so network is should be already up
Perhaps you have to add the path to the su command and also try some other variations:
Code:
/bin/su user1 -c "/home/user1/bash_scripts/start_synergy.bash"
 
Old 05-06-2014, 11:33 AM   #9
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Original Poster
Rep: Reputation: 1
Alright. I admit it. I did not RTFM: http://synergy2.sourceforge.net/autostart.html

It says right in the documentation for Synergy in easy to follow directions how to start synergy before login. It was very simple and I had it up and running the way I wanted in a few short minutes. Feel really stupid now for making this thread for nothing.

For those of you too lazy to look at the link:
synergy requires X server to be running before it can run. That means it needs to be started with the desktop manager. In my case (gnome) I edited three files in the /etc/gdm folder. Works like a charm.

If you need me I will be in the corner with my dunce cap on.
 
  


Reply



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
super user privileges check for a normal user in bash script freeindy Programming 2 08-01-2008 06:08 AM
User executable script gaining root privileges w/o passwd neoAKiRAz Linux - General 6 09-06-2007 04:22 PM
Script with root privileges running by an ordinary user MOCKBA Linux - Newbie 3 02-09-2007 03:33 PM
mySQL - local user privileges Genjix Programming 2 12-03-2004 08:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

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

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
Open Source Consulting | Domain Registration