Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 7th October 2013, 11:37
wisecu90 wisecu90 is offline
Junior Member
 
Join Date: Oct 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question bash Script to change username

I'd like to create a script to change multiple usernames in the /var/yp/ypfiles directory. I came up with something, but not quite what i want as there are about 100 users to rename. Any help would be appreciated. My initial idea is:

#!/bin/bash
#Test script to rename userID

#this first if statment has been test at home environment


count=$(grep FMachado7 /etc/passwd | wc -l);
if [ $count -eq 1 ]
then
sed -i 's/FMachado7/FMachado8/g' /etc/passwd
else
echo "number of entries for passwd is: $count"
fi


#this second if statment has been test at home environment


count1=$(grep FMachado7 /etc/shadow | wc -l);
if [ $count1 -eq 1 ]
then
sed -i 's/FMachado7/FMachado8/g' /etc/shadow
else
echo "number of entries for shadow is: $count1"
fi

#this third if statment has been test at home environment

count2=$(grep FMachado7 /etc/auto.home | wc -l);
if [ $count2 -eq 1 ]
then
sed -i 's/FMachado7/FMachado8/g' /etc/auto.home
else
echo "number of entries for auto.home is: $count2"
fi

this is based on whether there's only one entry for that user.is it possible to put the list of user in a array or something similar?
Reply With Quote
Sponsored Links
  #2  
Old 28th October 2013, 15:06
DaneilKevin DaneilKevin is offline
Junior Member
 
Join Date: Oct 2013
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
 
Default

It doesn't working any more..It shows an error on the seventh line...How I resolved it?
__________________
Check out Google drive management
Reply With Quote
The Following User Says Thank You to DaneilKevin For This Useful Post:
feeninuoumn (17th December 2013)
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Some questions about commands in bash script vl72 Programming/Scripts 1 6th March 2011 22:23
How to change default username khaoss Installation/Configuration 1 13th September 2009 14:23
accessing CGI-BIN / odd script behaviour jamesls Installation/Configuration 2 2nd August 2009 08:16
Change the admin username Master One Installation/Configuration 1 26th June 2009 00:25
Internet Explorer won't connect to my server wctaelectronics Server Operation 10 27th October 2008 22:14


All times are GMT +2. The time now is 16:54.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.