LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 12-15-2004, 03:56 PM   #1
lightningdan
LQ Newbie
 
Registered: Nov 2003
Posts: 14

Rep: Reputation: 0
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.
 
Old 12-15-2004, 04:09 PM   #2
sigsegv
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: Reputation: 47
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.
 
Old 12-15-2004, 05:20 PM   #3
lightningdan
LQ Newbie
 
Registered: Nov 2003
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 12-15-2004, 05:43 PM   #4
sigsegv
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: Reputation: 47
Why yes, yes I do

/me does a rockin' little dance
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Displaying Environment Variables movitto Linux - Networking 5 08-12-2005 10:51 AM
environment variables in c++ s3b0 Programming 6 08-27-2004 09:19 AM
environment variables kakridge Linux - Newbie 1 07-14-2003 06:25 PM
Environment variables kdnt Linux - Newbie 11 11-01-2002 08:19 AM
environment variables aethereal Linux - Newbie 7 12-19-2001 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration