I am working on a custom script to add/remove users to/from a chroot environment as well as backingup/restoring data (passwd/group files and user folders etc)..
So far so good mostly but im stumped on how to emulate the deluser function, to remove a line(the user instance) from a file(custom passwd file)..
You can see the script here:
http://files.serverhash.com/Debian%7cUbuntu/chroot_ssh/chroot_ssh.txtAnd some notes and general info about it here:
http://files.serverhash.com/Debian%7cUbuntu/chroot_ssh/readme.txtThe Deluser function is nearly complete, I just need a way to delete the user data stored from:
deluser=`grep $chrootdir/etc/passwd -e "^$username"`
I am reading up on sed and cat as they seem to be usefull for what I need to do but im unfamiliar with them.
Could someone post an example of using grep similar to what im doing above to pull a line from a file, then show an example of how to delete that line from the file I would appreciate it.
Update:
Got this working basicially maybe a better ways.
touch $chrootdir/etc/passwd.bak
sed -e "/$username/d" < $chrootdir/etc/passwd > $chrootdir/etc/passwd.bak
rm -rf $chrootdir/etc/passwd
cp $chrootdir/etc/passwd.bak $chrootdir/etc/passwd
rm -rf $chrootdir/etc/passwd.bak
Any suggestions appreciated..