0

I have a bash script that runs over crontab as root.

On the bottom of that script I want to run another bash script as another user in a subshell (detached).

How can I do that

The normal command would be

/bin/bash /path/myscript.sh

Thanks in advance.

Omexlu
  • 43
  • 1
  • 9
  • I haven't tested it, but something like: `su otheruser -c /path/myscript.sh &` might be a step in the right direction. Since the main script is running as root, it *should* not require otheruser's password - although doing this thru cron might be a little quirky. – Brandon Xavier May 15 '21 at 07:19

2 Answers2

0

I found an easy way:

/sbin/runuser -l USER -c 'COMMAND'

Works :)

Omexlu
  • 43
  • 1
  • 9
0

su - USER -c /path/myscript.sh

Is IMHO the easiest option, it's supposed, that /path/myscript.sh has executable permissions and the typical #! /bin/bash first line.

d.c.
  • 257
  • 1
  • 2
  • 8