Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> edit a file by script
mm1409
Posted: Apr 25 2005, 09:30 AM
Quote Post


Newbie
*

Group: Members
Posts: 2
Member No.: 941
Joined: 22-April 05



hello,

i have the following problem.

i create a new user with useradd in a shell by the following command:

useradd -c "$3" -d /home/ftp/$1 -g ftp -m -k /home/ftp/vorlage -s /bin/sh -p $(perl -e "print crypt('$2','UM');") $1
chmod 770 /home/ftp/$1/*

after that i have to correct entries in the passwd and the shadow file because the username contain only numeric and this wouldn`t work. so i create the user with an leading 'B'.

here is an example

B47600:x:1000:500:Muster, Test:/home/ftp/47600:/bin/sh

now i have to change directly the entry in both files (passwd and shadow). so it looks like:

47600:x:1000:500:Muster, Test:/home/ftp/47600:/bin/sh

how can i fix these entries?

michael

PMEmail Poster
Top
andyb1ack
Posted: Apr 26 2005, 03:55 PM
Quote Post


User Level: 4
****

Group: Members
Posts: 98
Member No.: 513
Joined: 9-September 04



Not recommended to change these files by hand, but if you really have to:

sed is the command to script files edits.
For example
sed '/^B47600:/47600:/' file1 > file2
mv file2 file1

Make sure you backup the passwd and shadow files before running the script!
PMEmail Poster
Top
mm1409
Posted: Apr 28 2005, 03:45 PM
Quote Post


Newbie
*

Group: Members
Posts: 2
Member No.: 941
Joined: 22-April 05



hello,

i think i found a better solution. here it is

...
useradd -c "$3" -d /home/ftp/$1 -g ftp -m -k /home/ftp/vorlage -s /bin/sh -p $(perl -e "print crypt('$2','UM');") $1
chmod 770 /home/ftp/$1/*
vi passwd << EOD
:%s/B47600/47600/g
:wq
EOD
vi shadow << EOD
:%s/B47600/47600/g
:wq
EOD
...
when i change the entry as i have shown, i donīt need a second file and move it back to the original file.

thanks for your help

PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Shells & Scripting | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.2472 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: Electronic Circuit Design :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum