Home dir renaming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Home dir renaming
# 1  
Old 03-29-2011
Home dir renaming

It is required to rename the home dir of some users specifed in the file ids.csv. But the code is not working as expected.

ids.csv have content in the format
id1,name,id2

It displays the expected message , still it is unable to rename the dirs
Find the code below:
Code:
#!/bin/ksh
CSV_FILE="/home/pde/docs/unix_xid/ids.csv";
#######  Read the csv file for unixid and xid ######
while IFS=, read UNIX_ID NAME NEW_ID
do
cd ~$UNIX_ID 2>>log_homedir_non_existent
if [ $? -eq 0 ] ;
then
 pwd
 cd .. 2>>log_homedir_cdparent_failed
 if [ $? -eq 0 ] ;
 then
  HOME_DIR_LOCATION=`pwd`
  echo $HOME_DIR_LOCATION
  mv $HOME_DIR_LOCATION/$UNIX_ID $HOME_DIR_LOCATION/$NEW_ID 2>>log_homedir_rename_failed
 
  if [ $? -eq 0 ] ;
  then
   echo "$UNIX_ID to $NEW_ID.................Done"
   echo "$UNIX_ID to $NEW_ID.................Done" >>log_homedir_rename_success
  else
   echo "$UNIX_ID to $NEW_ID.................Failed"
  fi
 else
  echo "Unable to cd parent $UNIX_ID"
 fi
else
 echo " $UNIX_ID directory does not exists........"
fi
done < $CSV_FILE

when run it displays the ID1 to ID2.................Done
but actual renaming is not done.
# 2  
Old 03-29-2011
1) what do you have in log_homedir_rename_failed of the corresponding ID ?

2) for your info :

Code:
echo "$UNIX_ID to $NEW_ID.................Done"
echo "$UNIX_ID to $NEW_ID.................Done" >>log_homedir_rename_success

shoud be replaced with
Code:
echo "$UNIX_ID to $NEW_ID.................Done" | tee -a log_homedir_rename_success

try change
Code:
mv $HOME_DIR_LOCATION/$UNIX_ID $HOME_DIR_LOCATION/$NEW_ID 2>>log_homedir_rename_failed


with (run it in a test environment first so that you can check it behaves as you expect)
Code:
mv $HOME_DIR_LOCATION/$UNIX_ID/* $HOME_DIR_LOCATION/$UNIX_ID/.??* $HOME_DIR_LOCATION/$NEW_ID 2>>log_homedir_rename_failed

or
Code:
cp -pr $HOME_DIR_LOCATION/$UNIX_ID/* $HOME_DIR_LOCATION/$NEW_ID/

and (after checking that nothing is missing)
Code:
rm -rf $HOME_DIR_LOCATION/$UNIX_ID

You could also look for some other find/cpio/rsync command to perform such kind of copy

Last edited by ctsgnb; 03-29-2011 at 11:04 AM..
# 3  
Old 03-29-2011
home dir renaming

Thanks for removing the duplicacy

There is nothing in the file log_homedir_rename_failed.

I don't think there is any problem with the code , but still unable to get expected result
# 4  
Old 03-29-2011
If you don't get the expected result, it means the code has a problem (maybe not in syntax, but still!)
Smilie

---------- Post updated at 04:12 PM ---------- Previous update was at 04:09 PM ----------

1) Use double quoting

2) For troubleshooting maybe you can echo the used values before doing the move :
Code:
echo "$HOME_DIR_LOCATION/$UNIX_ID $HOME_DIR_LOCATION/$NEW_ID"
mv "$HOME_DIR_LOCATION/$UNIX_ID" "$HOME_DIR_LOCATION/$NEW_ID"

instead of
Code:
echo $HOME_DIR_LOCATION
mv $HOME_DIR_LOCATION/$UNIX_ID $HOME_DIR_LOCATION/$NEW_ID

then give a test run and see if the output gives some clue
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

2. HP-UX

could not able change permission of /home dir

Hi i am new to this admin area . i have created user with name as "ab" and gave home dir as /home/ab . when i tried to create the /home/ab dir , i got he following error. "mkdir: Failed to make directory "/home/ab"; Operation not applicable " Thanks in advance . (1 Reply)
Discussion started by: expert
1 Replies

3. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

4. Solaris

home dir mount issue

Hi all, I have to mount my home directory in one box, by default everyone's home directory will mount in all unix boxes which we have. But we have unmounted these home directories from some boxes to keep the data as safe. So for automation purpose i need my home directory only in those boxes to... (2 Replies)
Discussion started by: raghu.iv85
2 Replies

5. Shell Programming and Scripting

home dir checking

Hi, I want suggestion about user home directories, checking. how i could calculate this. I have 200 Users. if home-dir-of-user1 > 250 MB -> print "OK" fi if home-dir-of-user1 > 500 MB > Print "Warning" fi if home-dir-of-user1 > 1000 MB > Print "Critical" fi Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

6. Solaris

need to restrict user to his home dir

Hello, i need to create a user who's access is restricted only to his home directory and below, i restricted his pty access by adding 'no-pty' to the options of the ssh key in authorized_keys file. However, sftp access still allows this user access to all my file system thanks (5 Replies)
Discussion started by: lidram
5 Replies

7. UNIX for Dummies Questions & Answers

Modify user home dir

I created a new user and assigned a certain home dir to tis user. I've noticed that this home dir (/export/home/test) is already assigned to other users. I really want to create a dedicated home dir for the new user. Can anyone tell me how I can modify this user with a new homedir? Thx for... (4 Replies)
Discussion started by: kris_devis
4 Replies

8. UNIX for Dummies Questions & Answers

root dir ? home dir ?

I am little bit confused when the words "root directory" and "home directory" and "parent directory" are used. Can anybody explains the difference. I am trying to list the names and protections levels and size of visible files in the root directory would it be correct if I just typed: ls... (2 Replies)
Discussion started by: hinman
2 Replies

9. HP-UX

Home dir for users

Hello all, Most of our users have the same home directory, I know it's weird but it has been like this before me and we don't want to change that for now. When creating a new user using command useradd, it is not allowing me to create it because it is using the home directory of someone else. I... (2 Replies)
Discussion started by: qfwfq
2 Replies

10. UNIX for Advanced & Expert Users

removing a dir named: $HOME

How do I remove a directory named: $HOME $ rm "$HOME" rm: $HOME is a directory $ rmdir "$HOME" rmdir: directory "/home/bob": Directory is a mount point or in use (4 Replies)
Discussion started by: natter
4 Replies
Login or Register to Ask a Question