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.

  • 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 at 7:19

I found an easy way:

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

Works :)


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.