Add users from a text file to a Drupal User Role

Hypertufa Mix
Hypertufa Garden Pots @ 10 years

Add users from a text file to a Drupal User Role

#!/bin/bash

# Add Users To a Specific Role
# Setup These Variables

# Set Site Path
sitepath="/opt/var/www/htdocs/"

# Set Site Name
site="example.com"

# add user to ContentAuthor
#echo "Add users to ContentAuthor role"
cat example-users.txt | while read line
do
drush -d -r $sitepath -u 1 -l $site user-add-role "ContentAuthor" $line

#echo $line
done

###
# Command user-add-role needs a higher bootstrap level to run - you    [error] will need to invoke drush from a more functional Drupal environment to run this command

echo 'export PATH=/usr/bin:$PATH' >> ~/.profile
source ~/.profile
 

#####################
#
# Drupal 7 Example - used for printing fields in template files
# Check if a field exists, then do something

$public_field_location = field_get_items('node', $node, 'field_public_display_location');

if ($public_field_location) {
// do something
echo "<div id=\"node_section\"><h2> Where: </h2><div id=\"node_section_text\"> ";
print render($content['field_public_display_location']);
echo "</div></div>";
} else {
echo " No public location Set" ;
}

# Rename a Drupal user with Drush
drush sql-query "update users set name='new_name' where uid=4087"