Sponsored Content
Top Forums Shell Programming and Scripting Script to add new users to a group on multiple servers using SSH Post 302880890 by port43 on Tuesday 24th of December 2013 12:13:33 PM
Old 12-24-2013
What do you have so far?

---------- Post updated at 12:13 PM ---------- Previous update was at 08:27 AM ----------

... and let the bleeding commence.

It's been a while and I'm sure this is over complicated:
Code:
#!/bin/ksh

if [ $# -lt 3 ]; then
    print "usage: $0 <group> <userID> <serverfile>"
    exit 1
fi

NEWGROUP=$1
NEWUSER=$2
SERVERFILE=$3

for SERVER in `cat ${SERVERFILE}`
do
    if [ -n "`ping -c1 ${SERVER} 2>/dev/null | grep icmp_seq`" ]; then
        ISGROUP=`ssh ${SERVER} grep ${NEWGROUP} /etc/group`
        if [ ! -z "${ISGROUP}" ]; then
            ISUSER=`ssh ${SERVER} grep ${NEWUSER} /etc/passwd`
            if [ ! -z "${ISUSER}" ]; then
                ssh ${SERVER} usermod -g ${NEWGROUP} ${NEWUSER}
            else
                print "${NEWUSER} does not exist on ${SERVER}"
            fi
        else
            print "${NEWGROUP} does not exist on ${SERVER}"
        fi
    else
        print "${SERVER} is not reachable"
    fi
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to create users on many servers

Hi all, working on script to create a user acct on all our servers. for i in `cat $host_file`; do ssh $i /usr/bin/sudo /usr/bin/mkuser id='bpadm' gecos='NetBackup Admin' 2>&1 >> $log done error i get is: 3004-692 Error changing "id" to "bpadm" : Value is invalid. I have tried this in... (1 Reply)
Discussion started by: dnidiffer
1 Replies

2. Shell Programming and Scripting

command to add users to group

does a command exist to add users to more than one group? i think the usermod command can do this but i'm not really sure. past ways of me doing this has always been to just hack the /etc/group file and put the user in whatever group i need him to be in. however, vi..ing files like /etc/groups... (2 Replies)
Discussion started by: Terrible
2 Replies

3. Shell Programming and Scripting

SSH for a group of users ?

Hi, Can any one tell me is it possible to setup private key public key pairing(SSH ) for a group of users , instead of setting it up for individual users ? Eg: Say i have 3 users A,B and C and i want the users to connect to SERVER1. instead of generating public private keys for each user , is... (3 Replies)
Discussion started by: deepusunil
3 Replies

4. UNIX for Dummies Questions & Answers

SSH into multiple linux servers

Hi All, Okay, I need help. I need to ssh in to multiple linux servers execute certain commands and get them to email and print on the screen when the script is being executed. So below is my script. Its not working :-(. #!/bin/bash #linux/UNIX box with ssh key based login... (7 Replies)
Discussion started by: xytiz
7 Replies

5. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

6. Shell Programming and Scripting

Shell script to connect to multiple ssh servers

Hello, I have access to several linux servers (mostly centos based) located in a DC in another country. from day to day I need to login to each of them to do some work (they dont have gui/window manager installed, I work only from console), or even to just do a check like df -h for disc usage.... (3 Replies)
Discussion started by: MaRiOsGR
3 Replies

7. Shell Programming and Scripting

I need to add 30 users to 50 servers

Hi Y'all, I need help adding 30 users to 50 servers. Is there a way to automate this? I'm using this command: sudo mkuser pgrp=srvadm gecos=Spears, Brittney auditclasses=ALL sugroups=system,security user01 But I'm doing it per user, per server...HOW CAN I MAKE THIS EASIER?... (7 Replies)
Discussion started by: jennie28n
7 Replies

8. Shell Programming and Scripting

Script to delete users in the servers

Hi Team, Hope you are doing good.I am new to scripting.I have a requirement of deleting around 10 users in 100 servers.It is very time consuming by logging into each servers and delete the user.Here I have redhat 6 ,Suse linux 10&11 environment servers. In one set of servers I have... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

9. Shell Programming and Scripting

Appending authorized_keys on multiple servers using ssh

Hi I have an ssh 'for' loop script to login and put a key on multiple servers. I need to append a file on each server but the command which works ok from the prompt does not work via the script. I have cat filename | ssh user@servername "cat >>append.file.name" I have tried to 'spawn' this in... (0 Replies)
Discussion started by: Grueben
0 Replies

10. UNIX for Beginners Questions & Answers

ssh multiple servers

Hi folks. I'm pretty new to unix, while I'm learning a lot I'm finding bash scripting quite confusing. Im sure it's not really, my head just hasn't clicked with it. Anyway, I need a script to loop the ip addresses stored in a file and run a "pgrep <process>" and return the pid or some... (2 Replies)
Discussion started by: MuntyScrunt
2 Replies
GLOBUS-GRIDFTP-SERVER-SETUP-CHROOT(8)				  Globus Toolkit			     GLOBUS-GRIDFTP-SERVER-SETUP-CHROOT(8)

NAME
globus-gridftp-server-setup-chroot - creates the specific contents of a directory that can specified as a root of the file system tree exposed by the Globus GridFTP server SYNOPSYS
globus-gridftp-server-setup-chroot [-c certificate_dir] -r chroot_path_to_create DESCRIPTION
GridFTP server can be configured to restrict access to specific path using the command line option -chroot-path of the globus-gridftp- server command. The specified path will become the new root after authentication. That path must contain a valid certificate structure, and the files /etc/passwd and /etc/groups. The command globus-gridftp-server-setup-chroot helps creating such a suitable directory structure. OPTIONS
-r chroot_path_to_create Creates in chroot_path_to_create the directory structure expected by the globus-gridftp-server command, when started with -chroot- path command line option. -c certificate_dir Specifies explicitly the directory from which the certificates will be copied into the directory chroot_path_to_create. The default path is /etc/grid-security/certificates. AUTHOR
Initiative for Globus in Europe (IGE), http://www.ige-project.eu COPYRIGHT
Copyright (C) 2012 Initiative for Globus in Europe (IGE) SEE ALSO
globus-gridftp-server(8) February 16th, 2012 GLOBUS-GRIDFTP-SERVER-SETUP-CHROOT(8)
All times are GMT -4. The time now is 12:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy