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.

1
  • 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. Commented May 15, 2021 at 7:19

2 Answers 2

0

I found an easy way:

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

Works :)

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.

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.