I am writing a Shell Script where I have to delete a file on a remote machine via a Shell Script.
.. then at domain:
cd ./some/where rm some_file.war
How to accomplish that task?
You can pass the
ssh client a command to execute in place of starting a shell by appending it to the ssh command.
ssh firstname.lastname@example.org 'rm /some/where/some_file.war'
You don't have to
cd to a location to remove something as long as you specify the full path, so thats another step you can skip.
The next question is authentication. If you just run that, you will get prompted for a password. If you don't want to enter this interactively you should set up publickey authentication.
If you wish to delete remote file with the use of sudo, you need to execute something like this:
ssh -tt user@host 'stty raw -echo; sudo rm /path/to/file' < <(cat)
The ssh command has a command parameter (last parameter in the command) that you can use to run remote commands.
Setup passwordless keys then add the command as part of the ssh command. See: http://www.dotkam.com/2009/03/10/run-commands-remotely-via-ssh-with-no-password/