leohoward
leohoward

Reputation: 39

Exit Plink when command finishes

I'm trying run multiple command lines via plink.exe. After batch is finished. I want to exit this and execute new command line

My script in execute.bat file

(
echo cd /appl/
echo sudo -s
echo cd apache-tomcat/webapps/Test
echo sh ./J50X100.sh
) | plink.exe -batch host -l user -pw pass

Actual: It's still in remote, I cannot execute new command line

Actual details here

Expected: Exit this and is able to execute new command line

Upvotes: 3

Views: 7207

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202504

The way you are using Plink, it opens an interactive shell session. As with every interactive shell session, it has to be exited with exit command. In you case, with two exit commands actually, first to exit sudo, then to exit the login shell.


Though you better avoid using the interactive shell altogether by specifying the command on Plink command line:

plink.exe -batch host -l user -pw pass "cd /appl/ ; sudo -s 'cd apache-tomcat/webapps/Test ; sh ./J50X100.sh '"

Though this approach might be problematic with your specific case, as you will have to configure sudo to allow this command – But you should do it, as it is the right approach. You have to edit sudoers file – Ideally, you should create a script that does cd apache-tomcat/webapps/Test ; sh ./J50X100.sh and allow that script in sudoers.

Upvotes: 2

Related Questions