RHEL5 script

hi,
I have RHEL5 .
I have made 50 users in that.
with the name user1 user2....user50.

they all work in there home directory.
there home directory will be in
/user1/home/
now i want to make a script with the help of which everyday i can delete the content inside the home directory of every user.

any help will be appreciated
jatender
JATENDER1979Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

joolsSenior Systems AdministratorCommented:
why not just delete the users and re-create them?

userdel -r user<xx>
useradd <options> user<xx>
0
joolsSenior Systems AdministratorCommented:
something like;

for i in `ls -1 user*`
do
   userdel -r $i
   useradd $i
done

You can recreate passwords in the script, I cant remember the options at the moment.

or, to answer your question
for i in `ls -1 user*`
do
   rm -rf ~$i/*
done

best check it before it runs though :-)
0
omarfaridCommented:
try

i=1
while [ $i -le 50 ]
do
   rm -r ~/user$i/*
   rm -r ~/user$i/.[a-zA-Z0-9]*
done
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

joolsSenior Systems AdministratorCommented:
omar,

will i always = 1?
just wondering etc.
0
omarfaridCommented:
You are right :)

Sorry for missing that, here the script again:

i=1
while [ $i -le 50 ]
do
   rm -r ~/user$i/*
   rm -r ~/user$i/.[a-zA-Z0-9]*
   i=`expr $i + 1`
done
0
joolsSenior Systems AdministratorCommented:
:-)

I guess mine should read;
for i in `ls -1 /home/user*`
do
   rm -rf ~$i/*
done

I left the . files on purpose because of profiles and stuff.
0
omarfaridCommented:
two comments:

- the home dir as per the question is /user/home

- my script needs modification

i=1
while [ $i -le 50 ]
do
   rm -r ~user$i/*
   rm -r ~user$i/.[a-zA-Z0-9]*
   i=`expr $i + 1`
done

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.