- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: useradd script question
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
Discussions
Discussions
Forums
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
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
тАО12-10-2009 03:28 PM
тАО12-10-2009 03:28 PM
If I use ssh command in the script it uses only user1:
for i in `cat hosts`
do
echo "Adding users on $i"
cat user_list | while read uid comment
do
echo "Adding user $uid on host $i"
ssh -q $i useradd -c \"$comment\" -g users -d /home/$uid -s /usr/bin/ksh -m -k /etc/skel $uid
#echo $i $uid $comment
done
done
This is the output:
root @ host3 [/var/tmp/scripts]
# ./useradd.sh
Adding users on host1
Adding user user1 on host host1
host1 user1 users1 test
Adding users on host2
Adding user user1 on host host2
host2 user1 users1 test
root @ host3 [/var/tmp/scripts]
#
If I comment out ssh command and just use echo command it takes all 3 users for each host, so something is wrong with ssh command I am using, can you please help me with that:
root @ host3 [/var/tmp/scripts]
# vi useradd.sh
for i in `cat hosts`
do
echo "Adding users on $i"
cat user_list | while read uid comment
do
echo "Adding user $uid on host $i"
###ssh -q $i useradd -c \"$comment\" -g users -d /home/$uid -s /usr/bin/ksh -m -k /etc/skel $uid
echo $i $uid $comment
done
done
The output is good when ssh is commented out:
root @ host3 [/var/tmp/scripts]
# ./useradd.sh
Adding users on host1
Adding user user1 on host host1
host1 user1 users1 test
Adding user user2 on host host1
host1 user2 users2 test
Adding user user3 on host host1
host1 user3 users3 test
Adding users on host2
Adding user user1 on host host2
host2 user1 users1 test
Adding user user2 on host host2
host2 user2 users2 test
Adding user user3 on host host2
host2 user3 users3 test
root @ host3 [/var/tmp/scripts]
#
So, how can I use the ssh inside those 2 loops to make it working for all3 users to add to 2 hosts ?
I also found that it does not work with any ssh commands, even if I did "ssh host1 ll" inside that wile loop
if I do ll locally it works with all 3 users,
Also if I use only 1st "for" loop and use the fixed user it works.
Thank you.
Mike.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2009 03:47 PM
тАО12-10-2009 03:47 PM
Re: useradd script question
Add the '-n' option :
# ssh -q $i -n useradd -c \"$comment\" -g users -d /home/$uid -s /usr/bin/ksh -m -k /etc/skel $uid
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2009 03:52 PM
тАО12-10-2009 03:52 PM
Re: useradd script question
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2009 04:00 PM
тАО12-10-2009 04:00 PM
Solution> Thank you very much it is working, it is quick and great.
I'm happy to have helped. Help future readers find useful answers too by taking a few minutes to read:
https://forums13.itrc.hp.com/service/forums/helptips.do?#28
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2009 04:06 PM
тАО12-10-2009 04:06 PM
Re: useradd script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2009 04:38 PM
тАО12-10-2009 04:38 PM
Re: useradd script question
I got one more question,
I am using the same script to reset the passwd and instead of useradd command I use:
ssh -t $i -n passwd $uid inside the while loop, but it does not work, giving me the error:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Changing password for user3
pam_chauthtok: System error
Is there any way it can be fixed, and is there any way some how to input the hardcoded passwd ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 01:18 AM
тАО12-11-2009 01:18 AM
Re: useradd script question
You might look in other threads for useradd.sam.
>ssh -t $i -n passwd $uid .. but it does not work, giving me the error:
>Pseudo-terminal will not be allocated because stdin is not a terminal.
You need that -n to work with loops. But that -n is preventing passwd from working. Catch-22.
>is there any way some how to input the hardcoded passwd?
useradd.sam?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 08:24 AM
тАО12-11-2009 08:24 AM
Re: useradd script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 04:15 PM
тАО12-11-2009 04:15 PM
Re: useradd script question
or do you have sny other ideas how to reset passwd on the servers remotely via ssh ???
Thank you.
Mike.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 04:37 PM
тАО12-11-2009 04:37 PM
Re: useradd script question
Check below Link
http://www.unix.com/unix-advanced-expert-users/43352-using-ssh-change-password-remotely.html