Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Running script file from Pattern as another user using sudo -u command

Henrik Jutterst
Kilo Sage

In my custom pattern I need to run a script file on a Linux server. The file gets uploaded in my pattern via MID-server but the file needs to be executed as user_x.

But I just found out that I can't switch user using sudo su user_x command and that I need to run it like this:

sudo -u user_x myUploadedFile.sh

How is that done in the pattern? Here are my steps:

find_real_file.png

 

find_real_file.png

 

So, what do I do in step 3 to execute the file using the sudo -u command?

Thanks!

Edit: Found this thread, and it's basically the same but without a resolution. Adding the sudo -u command in the file did not solve the issue. Running a command on linux under sudo -u

1 ACCEPTED SOLUTION

Henrik Jutterst
Kilo Sage

Ok. So I asked around and got some feedback and tried a new approach and it seems to be doing what I want. Here's a screen shot of what the step in pattern looks like:

find_real_file.png

 

The output from Discovery Log gives me this:

Parse Command Output
2020-10-15 21:09:09: Executing SSH command: sudo -u <user_x> "/tmp/<foldername>/myUploadedFile.sh"
2020-10-15 21:09:11: Command result: sudo: unable to execute /tmp/<foldername>/myUploadedFile.sh: Permission denied
2020-10-15 21:09:11: Command failed with status 1
2020-10-15 21:09:11: Execution time: 2235 ms

 

I need to make sure correct permissions are set to file but this looks promising!

View solution in original post

12 REPLIES 12

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Henrik Jutterstrƶm,

We had a previous conversation here below, where I suggested some recommendation.

https://community.servicenow.com/community?id=community_question&sys_id=a2a7d3c0dbbc18105129a851ca96...

Just checking if this had helped you?

Please mark Helpful / Accept Solution so that it helps others with similar questions.

Hi and thanks for helping out. Unfortunetly I can not run that command since it's locked down. I need to run the sudo -u command as the discovery user. 

By the way, It seems that you posted the same link 4 times šŸ™‚

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Henrik Jutterstrƶm,

We had a same discussion here, jus want to check whether this had helped you in any way?

Please mark Helpful / Accept Solution so that it helps others with similar questions.

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Henrik Jutterstrƶm,

Did you get to check this, we had a discussion reg the same.

https://community.servicenow.com/community?id=community_question&sys_id=a2a7d3c0dbbc18105129a851ca96...

Please mark Helpful / Accept Solution so that it helps others with similar questions.