1

Due to conflicting and constantly changing permissions on mounted drives (which cannot easily be solved due to the development structure of programs), there is a script that must be run with root permissions.

This can be done with sudo /usr/serverm1/lsintd and provides good results. However, we wish to run this script automatically on startup.

Running the script under our main user on startup results in a core dump due to insufficient permissions. Therefore, we figured we could set it in crontab as @reboot /usr/serverm1/lsintd (as suggested here, however this runs it with settings and config from root (which is non existent).

TLDR: How can we run the script exactly as it would run with the command sudo /usr/serverm1/lsintd on startup?

I also tried applying chmod u+x to the binary, however this still resulted in a core dump as if run with regular perms (idea taken from let a user run a script with root permissions).

Side note: I admit this is somewhat an XY problem, however due to the slow and poorly organized development structure of some of the other services on our server, we have no way of solving the root issues and must instead workaround with this.

3
  • Is sudo configured to require a password? Commented Dec 17, 2020 at 5:35
  • Yes it does require a password. Commented Dec 17, 2020 at 13:33
  • How are you handling that requirement in your cron job? Commented Dec 17, 2020 at 16:17

1 Answer 1

2

One way would be to create a systemd unit.
All the possible options you can find here: www.freedesktop.org/.../systemd.unit.html but I am going to present simple example:

1.Lets create a bash script which will write the date and time of each system bootup to the file: /root/file
Only root user has permissions to write and edit files in /root directory.
I am going to switch user to the root with sudo su -
Lets create a script /root/timelog.sh and make it executable chmod +x /root/timelog.sh

 #!/bin/bash if ! [ /root/file ]; then touch /root/file; fi echo $(date) >> /root/file 

2.Now we need the System Unit file: /etc/systemd/system/timelog.service

[Unit] Description=timelog.service [Service] Type=oneshot ExecStart=/root/timelog.sh [Install] WantedBy=multi-user.target 

3.Last task is to make sure it will start with the system:

systemctl enable timelog 
6
  • Genius! I never considered making it into a service. Of course! Thank you Romank! Commented Dec 17, 2020 at 13:33
  • @MarkDeven If this answered your question, would you select it as an answer? Thanks. Commented Dec 17, 2020 at 17:21
  • Yes @RomanK, sorry for the delay in doing so. Christmas season and all. Commented Dec 26, 2020 at 23:33
  • the software is giving an error since the script requires an X display. Any ideas how to make it use the default :0 display? I tried Environment=DISPLAY:0.0. Commented Dec 26, 2020 at 23:52
  • @MarkDeven This question will fork significantly from the original question but check if THIS answers it. Commented Dec 27, 2020 at 5:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.