-2

I want to write a shell script to connect to the remote server and execute a command (any linux command).

I am using linux and want to prepare a shell script which can login to the virtual directory server and execute a given command.

I.e. if I want to execute the imqcmd command, how can I do this?

closed as unclear what you're asking by Kilian Foth, Arseni Mourzenko, Jörg W Mittag, GlenH7, gnat May 26 '14 at 13:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question. – gnat May 26 '14 at 9:11
  • You could start with mentioning what operating system you are using on client and server. – Philipp May 26 '14 at 9:24
  • I am using linux and want to prepare a shell script which can login to the virtual directory server and execute a given command i.e if i want to execute imqcmd command . how can i do this? – user3664498 May 26 '14 at 9:26
  • You apparently also want the remote command to ask for user input. Are there any other requirements not shown in the question? Could you say exactly what you want it to do? – Useless May 26 '14 at 11:03
  • 2
    belongs on unix/linux site, not programmers – Michael Durrant May 26 '14 at 11:05
-1

This is the direct ssh command for command execution it asks for password after you enter this command. Any way the below shell script shall work.

#!/bin/bash ssh root@ipaddress yourcommand

  • And if after executing the command again it asks for the user input i.e user and password then what shall be added here? – user3664498 May 26 '14 at 10:50
  • I mean you need to automate this command with providing password ??? – Rizwan S A May 26 '14 at 11:03
  • yes, providing username and password. – user3664498 May 26 '14 at 11:10
  • You cannot password embedded with this command. One possible solution is to generate the keys between two machines and provide the keys during ssh command. The below link will be helpful linuxproblem.org/art_9.html – Rizwan S A May 27 '14 at 5:47
  • Can't there be anyway out without generating keys? – user3664498 May 28 '14 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.