Reputation: 575
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
Upvotes: 0
Views: 5076
Reputation: 15793
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.
"ssh your_user@ssh_server ls /"
This command will log in, list the root directory, and closes the connection.
After the 1st pass succeeds, try to replace "ls /" with your script.
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
Upvotes: 2
Reputation: 650
Your script structure should be:
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.
Upvotes: 0