VMware Cloud Community
AviFreege
Contributor
Contributor

Sudo threw scriptable task is not working



Hi ,


I am trying to run a command using the scriptable task which requires SU to root, I notice I can't sudo and then run the command since its not the same shell, so I tried using the sudo -S command that will pull the password from the stdout:


session.connectWithPassword(password);



System.log("Connected!");


var cmd="echo 123456 | sudo -S sed -i '
''s/export TMOUT=120/export TMOUT=2400/g'
'' /etc/profile";

System.log("Executing "cmd"");


session.executeCommand(cmd,false) ;



If I am running this command on the server itself its working perfect.



Any idea whay?



Thanks,



Avi


0 Kudos
4 Replies
qc4vmware
Virtuoso
Virtuoso

what is the content of session.output after you run this?  I remember successfully running a similar command in my environment at some point.  I have since eliminated the need for sudo in that case and I don't have my old workflow around to compare what you are doing to.

0 Kudos
sagedining
Contributor
Contributor

you might have to find a way to specify that the password input coming from echo will be run to stdin. A script we have utilizes the echo to a pipe for SSH purposes...but the data from echo needs to be treated as standard input.

0 Kudos
qc4vmware
Virtuoso
Virtuoso

Also looking at your sample I see a lot of syntax errors... Is that code exactly as you have it in your workflow?  Can you try running something more simple such as

var cmd = "echo \"123456\" | sudo -S uptime";

I'd keep the password in quotes and make sure you have escaped characters correctly anywhere else necessary in your string.  Also make sure you use absolute paths where necessary.  You can use the "Run SSH Command" workflow to test this out and it will log all of the output for you.

0 Kudos
AviFreege
Contributor
Contributor

Hi,

Ok first of all I managed to get this thing worked Smiley Happy

So regarding the syntax it is correct, what I had to do is adding

session.pty=true;

and that solved the problem.

Thanks everyone for your help.

Avi

0 Kudos