How to run a shell script in another user without typing password

You can use sudo to do this. First, you need to modify the /etc/sudoers file to add a rule that allows the hudson user to become the other user for the script in question. Let's assume you have a user1 account that needs to run /usr/local/bin/my_script.sh.

Run visudo to modify the sudoers file, and add a like like:

hudson ALL=(user1) NOPASSWD: /usr/local/bin/my_script.sh

Then, use the following sudo command to run the script from hudson:

sudo -u user1 /usr/local/bin/my_script.sh

It's very important that you use visudo to modify the sudoers file in order to check the file for errors before putting it in place. Also, I'd suggest a quick read through man sudoers in order to clearly understand what the above does before adding it to your configuration.


Commenting the Defaults requiretty entry in /etc/sudoers or other included suders files should help.

As for the perl error - your're probably using a different PERL5LIB or a different perl binary for that user - and that won't get passed in sudo (unless you use -E or env_keep). Check your environment and possibly, permissions.