Pass Multiple Commands and Open Multiple Xterms via PSS

Hello,

I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else afterwards.
I've tried many combinations and I'm not sure if my options for the pssh nor the xterm options are set correctly....Here is what I have now..

pssh -i -h ectsrv -A -O StrictHostKeyChecking=no "export DISPLAY=IP address:0.0;  xterm -hold -e "sudo /path/sap_sudo.sh" " 

I've tried many combinations..with and without quotes of single and double:

xterm -e sudo "cmd1;cmd2;ls;bash"
xterm -e sudo "cmd1 && cmd2"
xterm -e sudo "cmd1;cmd2; ksh"
xterm -e sudo "-tt" "cmd1;cmd2;ls;bash"

Completely stuck at SIDADM> in new windows, but it won't run commands afer...please assist!
Thanks for any feedback

No combination of quotes and semicolons is going to help when your shell code isn't being fed into a shell. xterm is not a shell, and won't understand cmd1;cmd2;...

Also, when you ssh through, your local shell may strip off the outer layer of quotes, turning it into xterm -e cmd1 ; cmd2 ; ls ; bash which is probably not what you want -- it will wait for xterm to quit before running the rest, outside!

To have xterm run a shell, tell xterm to run a shell. You can feed a string into most Bourne shells with the -c option.

xterm -e sudo bash -c "'cmd1;cmd2;ls;exec bash'"

I'm not 100% sure whether you need the extra ' ' when you run it with SAP or not. It depends whether your code gets fed into an actual shell, or just a dumb splitter. A dumb splitter might need exec\ bash to not split upon the space, even though its inside quotes.

...the 'exec bash' at the end should drop it to an interactive prompt. If it's not doing a good enough job of loading your profile, try exec bash -l .

How are you running sisadm? Give an example. I am not familiar with sisadm; however, perhaps you are hitting it in an interactive mode and there is a way to run it by redirecting it's standard input, or by a command line argument that points to a script containing sisadm commands.

As I understand it SAP is about as noninteractive as it gets, hence the desperate attempts to kludge a real, actual interactive shell into its one-way thinking.

Hey Thanks for all of your quick replies. I appreciate that!!

I'm able to sudo to my sap(adm) user via the sudo /path/sap_sudo.sh . So that part works well with all xterm windows at my user prompt
SAPADM>
Now if I can run command any unix or SAP command, which I can manually from these windows, such as ls -lrt , pwd , or R3trans -d then that would be crazy good. Imagine that and seeing the output on all systems in the different windows at the same time. :slight_smile: That's my goal.

I'll give

xterm -e sudo bash -c "'cmd1;cmd2;ls;exec bash'"

a try and then the exec bash -l .....

xterm -e sudo bash -c "'cmd1;cmd2;ls;exec bash'"

I've also tried

pssh -i -h ectsrv -A -O StrictHostKeyChecking=no "export DISPLAY=IP address:0.0; xterm -hold bash -e "sudo /path/sap_sudo.sh 'ls;whoami;bash -l" "

Multiple times in different ways...nothing.

However, I did try this

pssh -i -v -h ectsrv -A -O StrictHostKeyChecking=no "export DISPLAY=IP.IP.IP:0.0; xterm -hold -e ls; sudo /path/sap_sudo.sh ""

and the ls command worked, but as my userid and not the SID and the title of the XTERM was labled "ls"....

Unfortunately, it will sudo, but won't LS when the ls command is at the end per the earlier command...

Please assist. Thanks for any replies..

Well of course it won't. It has to be like this:

... xterm -e command ...

...because if you don't put the commands into xterm, they're not going to be in xterm.

Try just pssh -i -h ectsrv -A -O StrictHostKeyChecking=no "export DISPLAY=IP address:0.0; xterm -e bash" to see if you can at least get a terminal prompt. If you can get a terminal prompt, try and build from there.

You can use the -n and/or -T options to change the name displayed on the window and/or icon (if you iconify it).

And you CAN'T pass multiple commands to xterm:

xterm(1): terminal emulator for X - Linux man page

Thanks. I was able to get a prompt with my user id.

Attempted to build from there... with

pssh -i -v -h ectsrv -A -O StrictHostKeyChecking=no  "export DISPLAY=IP:0.0;  xterm -hold -e bash sudo /path/sap_sudo.sh"

got the error: /usr/bin/sudo: /usr/bin/sudo: cannot execute binary file

  • I also tried
/usr/bin/sudo /path/sap_sudo.sh

same error

What is /path/sap_sudo.sh ? What does it do? How is it used?

You're trying to feed bash something that's not a shell script... Namely, you're trying to feed it /usr/bin/sudo. Wouldn't you rather have sudo run bash instead? :slight_smile:

pssh -i -v -h ectsrv -A -O StrictHostKeyChecking=no "export DISPLAY=IP:0.0; xterm -hold -e sudo bash"

Hey I figured it out. I should've tried this in the first place, but
I was so determined on the other method.

Pssh -i -h server.txt ...."export display 1
Ip:0.0; xterm -e script.sh

In the script

Echo "cmd"|sudo /path/sudo script.sh"

And those xterms opened up simultaneously as the right user and executed
commands and displayed the output all each server like I wanted!!!

Thanks to everyone for all of your kind feedback in such a timely manner.

1 Like

I am very glad that you have something that is working for you. What shell are you using. Most shells would give you a syntax error for both of those commands due to unmatched double quotes.