reg adding Users into at.allow and removing from at.allow

Hi ,

Thanks for your time .

I am working on a application , which adds unix user through useradd and deletes user through userdel . both are admin commands .

My requirement is i have to add a user into at.allow whenver a unix user is added through my application and the user should be deleted from at.allow whenever a user is deleted from my application .
is there any way i can do this through a C program or a shell script .

for at.allow addition i can write a small script having a line
echo "Bill" >> /var/adm/at.allow .

but if i want to delete the same bill in at.allow , how can i delete from at.allow .
is there any specific way to do this through a command or a program.

IN simple words i have to update the file with new user and delete the existing user from at.allow.

many thanks for your time .

Cheers
Narendra

You can use a small script for deletion as well. Use grep/sed/awk/ex to remove the unwanted userid, output to a temp file, move the temp file back over the at.allow file.

Something like:

grep -v "Bill" /var/adm/at.allow > /tmp/at.allow.$$
mv /tmp/at.allow.$$ /var/adm/at.allow

grep/sed will require that you create a temp file, ex will allow the actual at.allow file to be edited.

ex /var/adm/at.allow <<EOF
/Bill
d
wq
EOF

Will remove the id Bill from the /var/adm/at.allow file.

Many Thanks Blowtorch for your answer .

But here i cannot solve concurrency issues , multiple users accessing the same file.
two people using at.allow may cause incosistent at.allow file .

so i have to locak it before i update it .

any information reg the same a C program to lock , remove and unlock the at.allow so that we can avoid concurrency issues .

many thanks
Narendra

Are you using a C program to do this or a shell script? You can use lockf in C. It allows record level locking of files, but if you do that, I am not sure that you can use another script to update the file.

Look at http://www.unix.com/showthread.php?t=28799&highlight=lock