0

I want to automate my support work. I want to make a script that will connect to a server and do some CRUD operation on the server and again return to local machine. I don't want to upload the script.Till now I have made a script that will help to connect to the server but i am not able to do any any other operations through. Is it possible to run a local script on the remote server?

My script:

!/usr/bin/expect 
  set ip neviss
  set user user 
  set password 1234 
  spawn ssh "$user\@$ip" 
  expect "Password:" 
  send "$password\r"; 
  interact ( after this line any command is not getting executed) 
  ls -lrt
0

3 Answers 3

2

You can do it so:

ssh user@remote-ssh-server "commands of script" 

If you keep the script into a file, you can do so:

ssh user@remote-ssh-server << End
paste the script here
End

Here are a few details.

  1. Log in with "ssh your_user@ssh_server ls /"

This command will log in, list the root directory, and closes the connection.

  1. After the 1st pass succeeds, try to replace "ls /" with your script.

  2. After the 2nd step succeeds, start a ssh agent.

Do not pass to step 2 before to finish the first step.

Use a ssh tutorial like this one -- this will help you

http://support.suso.com/supki/SSH_Tutorial_for_Linux

Sign up to request clarification or add additional context in comments.

9 Comments

hi alinsoar, thanks for the info .i have another doubt like if the command i want to execute will get executed only if i am logging into the server through the superuser, that means i ssh the server then i logged in as super user by firing a query "su - user" and then the password and then the commands i want to fire.
could please help like how can i add the superuser authentication into the script, so that when ever i run the script like "ssh user@remote < script.sh " i want to automate the superuserlogging in and then run the run script in the remote server . please help if you know anyway .will be thankful to you .
This will execute the script exactly as you run it locally as a user user viz., if you log as root, the script will be run with root priority.
ssh will not ask for a password if you initialize a ssh agent.
try to read a basic tutorial. I already told you more details than you needed to start working.
|
0

Your script structure should be:

  1. Connect via SSH.
  2. CRUD operations
  3. Exit SSH.

The script with CRUD operations has to be on the remote computer, because you can't run any script that isn't on the machine where you want to run it.

3 Comments

please be clear what ever you want to say there are two different things software and script . please aware about the difference between them.
you mean to say that i cant run a local script in a remote server right ?
You can't run a local script in a remote server. But if your remote server has the same software than your local machine, you can do it.
0
ssh user@server bash < /path/to/local/script.sh

1 Comment

how to add superuser authentication to with in the script .i means i want to run the script after i loged into the server as a superuser. please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.