FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Edubuntu User

 
 
LinkBack Thread Tools
 
Old 11-10-2009, 10:11 PM
Mika Pflüger
 
Default Script to move into each home and delete all .g* folders

Hi,

Am Tue, 10 Nov 2009 14:29:10 -0700
schrieb Jim Christiansen <jim.c.christiansen@gmail.com>:
> What I need to do is find a script that will:
>
> cd into each student home
> rm -rf .g*
> cd back out
> cd into the next student home and repeat all the way through the home
> dir
Before I make any suggestions, please consider:
.g* would match an awful lot of other stuff: Private keys
in .gnupg-folders, backups/versioning in .git-folders and similar.
Maybe you should rather make a list of what to delete

Make a backup, then try:
1. If you want to delete all those folders in all user's home
directories (not only student's):
rm -rf /home/*/.g*
Just type it into a terminal as root. But it is pretty brutal, as
stated above
2. If you want to delete only the student's folders:
rm -rf /home/{$(cat /etc/group|grep students|cut -d ':' -f4)}/.g*
Replace students with the name of the group of your students. Still
pretty brutal, but works if the group has more than one member.

But, you should use a better wildcard:
rm -rf /home/*/.{gnome,gnome2,gconf}
would be way better already. Note all user's settings will still be
lost, but better than losing their private keys.

So for all the students this would read:
rm -rf /home/{$(cat /etc/group|grep students|cut -d ':' -f4)}/.{gnome,gnome2,gconf}

of course you can add other offending stuff into the
{gnome,gnome2,gconf} list.

And PLEASE: Before you run this, make a backup and try the command
replacing "rm -rf" with "ls" -- it will show you what will be deleted.
Check the list carefully, as I can't guarantee those one-liners are
really what you need and if I understood you correctly.
Note that with many users you might run into the "command line too
long" error. Then we have to think about something else involving
loops or "find"s

Greetings,

Mika Pflüger
--
edubuntu-users mailing list
edubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
 
Old 11-10-2009, 10:51 PM
Robert Citek
 
Default Script to move into each home and delete all .g* folders

On Tue, Nov 10, 2009 at 6:11 PM, Mika Pflüger <mail@mikapflueger.de> wrote:
> And PLEASE: Before you run this, make a backup and try the command
> replacing "rm -rf" with "ls" -- it will show you what will be deleted.
> Check the list carefully, as I can't guarantee those one-liners are
> really what you need and if I understood you correctly.
> Note that with many users you might run into the "command line too
> long" error. Then we have to think about something else involving
> loops or "find"s

Here's another variation using "ls -lad" instead of "rm -rf":

students="foo bar bat"
for i in $students ; do
echo ==$i
cd /home/$i &&
ls -lad .g*
done

Adjust the student= line to your list of students. If the list of
folders looks good, then replace the "ls -lad" with "rm -rf". And I
concur with Mika: make a backup first.

Good luck and let us know how things go.

Regards,
- Robert

--
edubuntu-users mailing list
edubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
 
Old 11-11-2009, 01:41 AM
"Harry Sweet"
 
Default Script to move into each home and delete all .g* folders

I had a similar issue (had to replace all my users .mozilla folders) and
wrote this perl script. It could be adapted pretty quickly to do most anything to all users.

This bit parses the /etc/passwd file to get a list of all users
-----------------------------------
open (MYFILE, "/etc/passwd") || die "Problem reading file $!";
my @contents=<MYFILE>;
close (MYFILE);

foreach my $user(@contents){
my @users=split(/:/, $user);
my ($username, $password,$uid, $gid,$gecos, $home, $shell)=@users;

-----------------------
Then the system function can run any terminal command

system("mv $home/.mozilla $home/.mozillaold"); or whatever.

how about
system("rm -rf .g*");


Probably overkill for something you can do from command line, but it might be useful to other
folks even to generate a list of user info

foreach my $user(@contents){
my @users=split(/:/, $user);
my ($username, $password,$uid, $gid,$gecos, $home, $shell)=@users;
print "Name | $username | Home Folder | $home";
}

and so on.


************************************************** *reskel.pl**************************************** ******
#!/usr/bin/perl -w

use strict;
use File::Copy::Recursive qw(dircopy);

my $fromdir = qw (/etc/skel);

open (MYFILE, "/etc/passwd") || die "Problem reading file $!";
my @contents=<MYFILE>;
close (MYFILE);

foreach my $user(@contents){
my @users=split(/:/, $user);
my ($username, $password,$uid, $gid,$gecos, $home, $shell)=@users;

if ($uid > 1001 && -d $home){
print system("mv $home/.mozilla $home/.mozillaold");
system ("rm -r $home/.mozillaold");
print " Copying UserID $uid Group ID $gid to $home.
";
dircopy($fromdir, $home) or die("$!
");
system("chown -R $uid:$gid $home");
system ("rm -r $home/.mozillaold");
}
}

>>> Jim Christiansen <jim.c.christiansen@gmail.com> 11/10/09 4:29 PM >>>
OK, it looks like I've settled on Ubuntu 9.04 for our new/old- rehabbed LTSP
server.

I'm symlinking my old K12LTSP rsynced home from another drive into the file
system as the home.

My student homes from the K12LTSPEL5 system are full of all of the wrong
.gconf ... .gnome folders. On startup if they don't exist they are created
no prob. What I need to do is find a script that will:

cd into each student home
rm -rf .g*
cd back out
cd into the next student home and repeat all the way through the home dir

I'm not having any troubles with the authenticating I don't think. I've
appended the old user lines from the k12ltsp group, password and shadow
files into the new ones. My rsynced student homes have ownership and other
permissions preserved.

I think it should all work if it wasn't for all of the old gnome/gconf junk.

Ideas for the script??

Thanks, Jim

--
edubuntu-users mailing list
edubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
 
Old 11-12-2009, 12:01 AM
Jim Christiansen
 
Default Script to move into each home and delete all .g* folders

Thanks everyone for the help.* It is Remembrance Day here in Canada and I actually stayed home and didn't look at computers today...* Well, I tuned my homemade fuel injection computer in my old V8 Jeep, but that was for relaxation!


I'll get to work on it tomorrow figure it out.

Thanks again :-)

--
edubuntu-users mailing list
edubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
 
Old 11-12-2009, 08:32 PM
Jim Christiansen
 
Default Script to move into each home and delete all .g* folders

I used Mika Pflüger's rm -rf /home/*/.g* and it worked like a charm.* I didn't know wildcards could be chained together like that.


Thanks.

--
edubuntu-users mailing list
edubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
 

Thread Tools




All times are GMT. The time now is 05:55 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org