Sponsored Content
Top Forums Shell Programming and Scripting Assigning variable from command outputs to shell Post 302329448 by staze on Saturday 27th of June 2009 11:40:28 PM
Old 06-28-2009
yeah, I figured out id was outputting the "no such user" to stderr just a moment ago.

Your suggestion worked brilliantly.

Thanks!

---------- Post updated at 08:40 PM ---------- Previous update was at 07:42 PM ----------

Incase anyone's interested, here's the "draft 1". It could be streamlined more, and I also plan to add the ability to delete members, and maybe compare the group against the input, and only add/remove those users that differ.

Feel free to use, though, I doubt it's worth much to people other than myself. =)

Code:
#!/bin/bash

#This script will take two arguments, the group name, and the user list. 
#It is recommended that the group be cleared before running this script since
#it will not remove people from the group.

dirnode="/LDAPv3/ldap.example.com"

if [ "$#" != "2" ]; then
echo -e "Usage of the groupadd script: $0 groupname userlist\n"
exit 1
else


echo "The following users do not exist in the directory" > ./non_existant_users.txt
group="$1"
userlist="$2"

echo "Adding users in $userlist to group $group"

read -p 'Enter username with directory write : ' admin
read -p 'Enter password for user : ' -s password

#echo "test user: $admin, test pass: $password"
echo "group: $group, userlist: $userlist"

for user in `cat $userlist`; do
	if ! id -u "$user" >/dev/null 2>&1; then
		echo "User $user does not exist!"
		non_existant="$non_existant $user"
	else
		exists="$exists $user"
	fi
done

for isuser in $exists; do
	#dseditgroup -o checkmember -m $isuser $group
	dseditgroup -o edit -n $dirnode -u $admin -P $password -a $isuser -t user $group
done

for nonuser in $non_existant; do
	echo $nonuser >> ./non_existant_users.txt
done

fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning a shell variable as a float

I'm confused as to how to handle floating point numbers in shell scripts. Is there a way to convert a number (string) read into a shell variable so that it can be used as a floating point decimal for calculation purposes? Or am I stuck with integrating C or Perl into my script? Ex: --input ... (3 Replies)
Discussion started by: spieterman
3 Replies

2. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

3. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

4. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

5. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

6. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

7. Shell Programming and Scripting

Assigning command to a variable

I've been searching these forums for a while, but this is my first actual post, so please bear with me :) I'm writing a short script using ksh and am trying to store a command and parameters in a variable. My intention is to issue the command by calling the variable. The command will contain... (4 Replies)
Discussion started by: makodarear
4 Replies

8. Shell Programming and Scripting

assigning fields variables value to shell variable

suppose I have a file named abc.txt.The contents of the file is sited below abc.txt maitree,test,test3 Using awk command can I store these 3 values in 3 different variable and in one single line command of awk. suppose variable a b c is there. I don't want like this a=`awk -F"," '{print... (2 Replies)
Discussion started by: maitree
2 Replies

9. Shell Programming and Scripting

[Solved] Assigning Shell variable

Hello, Need a small help to execute below script. #!/bin/bash . new.txt for no in 3 4 do echo $((uname_$no)) done new.txt contains uname_1="XXXXXX" uname_2="YYYYY" uname_3="ZZZZZ" ......... (6 Replies)
Discussion started by: prasanna2166
6 Replies

10. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 04:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy