Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
12-15-2004, 03:56 PM
|
#1
|
LQ Newbie
Registered: Nov 2003
Posts: 14
Rep:
|
retaining environment variables using ssh
Hi
Im trying to write a script to create an nis user (partly for fun, partly so other people can easily create accounts). I wanted to know how to go about logging into another machine, hopefully retaining my environment variables, and make a home directory (and change permissions and such). I run the script on the nis server already and it creates the new user with an incremented user id, adds stuff to the passwd file, etc. I also set up ssh keys so that I can log into the nfs server without requiring a password. How do I run the commands on the remote server though through ssh? I tried using:
echo command | ssh machinename
and that works for one command, but I will need to execute a few commands and
set up a few environment variables (which will change every time the script is run).
I tried to execute a script like
echo scriptname | ssh machinename
but that didnt seem to work right. Ive looked through the man pages for ssh and sshd, and nothing Ive seen looks like it will give me that capability. So,
1) Am I on drugs and I need to just forget about this, write two scripts, one to be run on each machine?
2) Is this possible using ssh, or should I look into another program? If so, which one?
3) Is this the best forum to post to?
Thanks a lot for your help and patience.
Dan
If more details are needed, please let me know.
|
|
|
12-15-2004, 04:09 PM
|
#2
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
1) I dunno, are you?  I'd probably do one script on each machine, but that's just a preference thing.
2) Yes, ssh hostname "command 1; command 2; command 3"
3) No idea.
|
|
|
12-15-2004, 05:20 PM
|
#3
|
LQ Newbie
Registered: Nov 2003
Posts: 14
Original Poster
Rep:
|
Thanks sigsegv, you rock.
Since my variables are already defined, it is easy just to do the ssh command
from inside the script, ssh -i identityfile host "mkdir /home/$username; chown $userid /home/$username" etc
|
|
|
12-15-2004, 05:43 PM
|
#4
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
Why yes, yes I do
/me does a rockin' little dance
|
|
|
All times are GMT -5. The time now is 02:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|