bash Script to change username

Discussion in 'Programming/Scripts' started by wisecu90, Oct 7, 2013.

  1. wisecu90

    wisecu90 New Member

    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?
     
  2. DaneilKevin

    DaneilKevin New Member

    It doesn't working any more..It shows an error on the seventh line...How I resolved it? :confused:
     

Share This Page