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

Henrik Jutterst
Tera Guru

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
Tera Guru

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,

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.

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

Out of curosity. did this command work from MID server to Target server?

Thanks,
Ashutosh

Hi Asutosh!

I just updated the case and I think you saw it.

In short: Yes, user was changed but it boiled down to this question where I need to run the script file as another user and not switch user.

But thanks for your respond and to all of you who are out here helping out!

Hi,

But still need an answer to this. Is that the answer in other thread?


Thanks,
Ashutosh

No it's not the answer to what I'm looking for.