Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Wasn't sure exactly were to post this as I couldn't see a scripting section?
Anyway I have created a bash script which logs me via ssh automatically. I then want it to perform further commands after login, however I cannot get this to work. I am connect to my linux server via a Mac OS X.
Please see script below any help is appreciated
#!/usr/bin/expect -f
spawn ssh root@192.168.0.40
expect "password:"
send "password here"
interact
sleep 2
send "service tor start"
send "service tor status"
end
Wasn't sure exactly were to post this as I couldn't see a scripting section?
Anyway I have created a bash script which logs me via ssh automatically. I then want it to perform further commands after login, however I cannot get this to work. I am connect to my linux server via a Mac OS X.
Please see script below any help is appreciated
#!/usr/bin/expect -f
spawn ssh root@192.168.0.40
expect "password:"
send "password here"
interact
sleep 2
send "service tor start"
send "service tor status"
end
Can you tell me why you are using expect?
FWIW, this would not really be a bash question, more of an expect quesxtion or an OpenSSH question.
The normal and supported way to automate ssh logon is to use certificates, rather than expect. Is there some reason you are not using certificates to automate logon?
Can you tell me why you are using expect?
FWIW, this would not really be a bash question, more of an expect quesxtion or an OpenSSH question.
The normal and supported way to automate ssh logon is to use certificates, rather than expect. Is there some reason you are not using certificates to automate logon?
Thanks for you reply.
Im not very good at scripting yet.
I copied the script from another forum online and modified it to my liking.
Is there a better way to do it?
The cert is already installed on my machine. The script will connect me to the SSH session with no problem at all.
Its the commands after e.g. service tor start
Forgive me, I did not make myself clear. Your expect script detects and responds to a password prompt. If your personal public cert were installed on the remote host there would be no password prompt.
You could run a command like
Code:
ssh root@192.168.0.40 uptime
and see the output of the command appear on the next line of your local terminal.
to run the two commands and then remain in session on the remote host. Check the man page for ssh, and google for examples. It is easier than you think.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.