- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Setting variable for remote ssh connection.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 10:57 PM
06-07-2005 10:57 PM
Setting variable for remote ssh connection.
Need help in executing the following.
i=server_name
group=sysadmin
ssh $i 'useradd -g $group -d /opt/home/x32810 -f 30 -s /bin/sh -c test -m x32810'
This is result i get.
Group -d specified with -g does not exist
pls. help
rgds
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 11:07 PM
06-07-2005 11:07 PM
Re: Setting variable for remote ssh connection.
ssh $i 'cat /etc/group|cut -f 1 -d :|grep sysadmin'
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 11:16 PM
06-07-2005 11:16 PM
Re: Setting variable for remote ssh connection.
Is group name getting effect in remote machine? Try to check it as,
ssh $i 'echo $group'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 11:27 PM
06-07-2005 11:27 PM
Re: Setting variable for remote ssh connection.
Actually the problem is with the passing of variable.
i need to know if the single quote is enough to pass $grp variable.
ssh $i 'useradd -g $group -d /opt/home/x32810 -f 30 -s /bin/sh -c test -m x32810'
Group -d specified with -g does not exist
Its is not takin the $group variable
waitin
rgds
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 11:30 PM
06-07-2005 11:30 PM
Re: Setting variable for remote ssh connection.
You can do one thing as,
put group=sysamin in /etc/sshrc remote machine or $HOME/.ssh/rc file.
It will work.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 12:02 AM
06-08-2005 12:02 AM
Re: Setting variable for remote ssh connection.
i m doin this to create users and groups remotely from one server to another.
So need to use variables for groups and users.
rgd
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 12:32 AM
06-08-2005 12:32 AM
Re: Setting variable for remote ssh connection.
The reason $group isn't getting sent is because you have single quotes around the command line. In this case, you actually don't even need quotes but if you want them, use double quotes. The shell will then expand all variables and send the command to ${i}...
You don't have to do any of the things the previous posts were mentioning...
To script this whole thing, create a text file with contents like:
host1 user1 group1
host1 user2 group1
host2 user3 group2
host2 user4 group2
host2 user5 group3
...
host# user# group#
cat ${file} | while read host user group
do
ssh -l root ${host} /usr/sbin/useradd -g ${group} -d /opt/home/${user} -f 30 -s /bin/ksh -c test -m ${user}
done
HTH;
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 12:57 AM
06-08-2005 12:57 AM
Re: Setting variable for remote ssh connection.
you need to double quote the command line:
ssh $i "useradd -g $group -d /opt/home/x32810 -f 30 -s /bin/sh -c test -m x32810"
shell does not expand any variables if it is surrounded by single quote('). you should use double quote to expand them
Hope this helps,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 01:30 AM
06-08-2005 01:30 AM
Re: Setting variable for remote ssh connection.
You must use double quotes (") and not single quotes.
Tested in one of my machines, and it works!!
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 04:39 PM
06-08-2005 04:39 PM
Re: Setting variable for remote ssh connection.
according to what I tested on my servers you can get rid of the single quotes and you are all set.
thanks
Devesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 05:11 PM
06-08-2005 05:11 PM
Re: Setting variable for remote ssh connection.
Actually the double quotes of comment was also creating problems.
I m proud to be associated with this forum.
Thanks again.
rgds
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2005 05:12 PM
06-08-2005 05:12 PM
Re: Setting variable for remote ssh connection.
ssh $i " useradd -u 400 -g ${grp} -d /opt/home/x32810 -f 30 -s /bin/sh -c 'test user' -m xtest "
bye
Rgds
Ankur