change home directory by modifying passwd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change home directory by modifying passwd
# 8  
Old 09-21-2008
I used your suggestion, but doesnt work:

echo "Enter username to change home directory:";
read username;
echo "Enter new home directory path:";
read new_path;

awk -v user=$username -v path=$new_path 'BEGIN{FS=OFS=":"}$1==user{$6=$new_path}1' /etc/passwd;;
# 9  
Old 09-21-2008
Quote:
Originally Posted by tjay83
I used your suggestion, but doesnt work:

echo "Enter username to change home directory:";
read username;
echo "Enter new home directory path:";
read new_path;

awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=$new_path}1' /etc/passwd;;
Watch for typo and use a temp file to make the changes permanent.
# 10  
Old 09-21-2008
it again doent work
# 11  
Old 09-21-2008
Maybe if you can tell what shell are you scripting for?
Code:
echo $SHELL

and what part of your script is not working (Please post your script (copy/paste) and use the [code] tag's.), maybe we can help you.

Last edited by danmero; 09-22-2008 at 04:04 AM..
# 12  
Old 09-21-2008
danmero means 'doesn't work' is meaningless when it comes to getting it to work.
# 13  
Old 09-22-2008
echo "Enter username to change home directory:";
read username;
echo "Enter new home directory path:";
read new_path;

awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=$new_path}1' /etc/passwd;;


After I run above script, the home directory for the entered user doesnt change.
and also when I run the script entire /etc/passwd file is displayed.

The result of the echo $SHELL is:
/bin/bash
# 14  
Old 09-22-2008
awk don't edit files "in place", use a temporary file:

Code:
#!bin/sh

echo -n "Enter username to change home directory: "
read username

echo -n "Enter new home directory path: "
read new_path

awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=new_path}1' /etc/passwd > temp_file
mv temp_file /etc/passwd

You must have root permissions to run this script.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Advanced & Expert Users

Change sFTP home directory for particular user and from specific server

Hello Folks, Of course i came here for your favour :) How to set a defalult home directory for sFTP login ( at present users land in to their home directrory) when they connect from specific server. When server(A) sFTP's to Linux server(B) they land to thier home directory. I want... (5 Replies)
Discussion started by: Thala
5 Replies

3. UNIX for Dummies Questions & Answers

Extract user accounts and home directory from /etc/passwd.

I am trying to obtain all user accounts and their respective home directories. /etc/passwd contains the required information, but I want to filter it to only show the uid,username and home directory path. I am working on a Solaris 11 machine. I made a little headway so far, but I got stuck... (7 Replies)
Discussion started by: Hijanoqu
7 Replies

4. Shell Programming and Scripting

Modifying sed to only change last occurrence.

I'm using sed to switch integers (one or more digits) to the other side of the ':' colon. For example: "47593:23421" would then be "23421:47593". The way it functions right now, it is messing my settings file to use with gnuplot. The current command is: sed 's/\(*\):\(*\)/\2:\1/' out3 >... (3 Replies)
Discussion started by: D2K
3 Replies

5. Solaris

How to recycle old passwords by modifying /etc/passwd file ?

hi, has anyone here tried to recycle old passwords by copying something out of the passwd file and paste them back into the same passwd file ? can it work this way ? some of our applications passwords are expiring but they cannot be change due to application concerns, so therefore we must... (7 Replies)
Discussion started by: Exposure
7 Replies

6. 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

7. Shell Programming and Scripting

force to change password(by modifying /etc/shadow)

hi by modifying /etc/shadow how can I Force a change of password so that user has at least 1 week to login? I did it by using: echo "enter username to force password change" read user; chage -M 7 $user; How can I do it by modifying /etc/shadow?? (6 Replies)
Discussion started by: tjay83
6 Replies

8. Solaris

/etc/passwd $HOME

I would like to add a user with the following $HOME: /var/abc/AB!CD!DE/error yes - this directory actually exists on the system. I would like the user to log into the above directory. I have tried wrapping in single quotes (`) as well as using the escape (\) but I guess that I do not have... (9 Replies)
Discussion started by: andrewrgrayjr
9 Replies
Login or Register to Ask a Question