ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everybody,
I am trying to make a shell script which will access a server present in my local network whose ip is 172.26.31.2 through ssh and restarts the network service. Its port no. is 1952
My own ip is: 172.16.31.176
For accessing it i use:-
ssh -p 1952 172.16.31.2
But i am unable to write the part of script which will supply the password whenever it prompts for password.
***********************
For restarting the service i can use
service network restart
Shell used by me is : /bin/sh
I will be thankful to u all....if u help me for this..
You can use sshpass to pass the password onto the SSH session and execute the command. Also if you want to restart the network service be sure that the user you use to connect through SSH has permissions to do so. With sshpass you can open an ssh session like this:
You can use sshpass to pass the password onto the SSH session and execute the command. Also if you want to restart the network service be sure that the user you use to connect through SSH has permissions to do so. With sshpass you can open an ssh session like this:
By using this i am able to login to the server automatically after executing script, but i doesn't restarts the network service on server...When i manually logout from the server then it restarts the network service..
Script is written as :-
sshpass -p mypassword ssh -p portno 172.16.31.2
service network restart
What you posted as script isn't complete. Please post the complete content of your script if you don't mind and put it between code tags for readability. Or did you just run the command from the terminal?
Distribution: Fedora 22, Debian 8, Centos 6/7 for servers
Posts: 101
Rep:
why dont you just enter: ssh -p 1952 172.16.31.2 service network restart
It will prompt you for your password, run the command, return the output and then disconnect.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.