I posted this on the Linux section but after doing some search on the forum I find this section more appropriate, sorry!
Hey all,
We need to setup a squid-proxy for a hotel, and we need to do some automation on the users administration. For this we have created a solution based on a bash script and the NCSA authentication system.
The script that we use to insert users that will be able to navigate via proxy inserts the usernames in the /etc/squid/htpasswd file and creates a second csv file described below:
prova1.prova1,1273781005
prova2.prova2,1273781016
prova3.prova3,1273781035
Where:
the first field is username composed by firstname.lastname,
the second field number is the timestamp in which users must be deleted
What I need is one or two scripts (Your advice here would be helpful) in order to:
1. grep all user's that have a minor timestamp than now (date --date="now" +%s).
2. delete those users using the htpasswd system and command which is:
htpasswd -D /etc/squid/passwd username
Anyone could help me?
Here's a script that I tried to adapt but couldn't make it because of lack of bash knowledge:
Delete User Script
#!/bin/bash
echo "Assignment1"
if [ "$(whoami)" != "root" ]
then
echo "Error: You ARE NOT ROOT!!!!!"
exit 1
else
echo "You are Lucky! I am watching you!!"
echo "Please enter the CSV"
read CSVFILE
exec < $CSVFILE
while
read line
do
firstName=$(echo $line | awk -F, '{print $1'})
lastName=$(echo $line | awk -F, '{print $2'})
idNumber=$(echo $line | awk -F, '{print $3'})
firstInit=$(echo $line | cut -c1)
userName=$lastName$firstInit
userName=$(echo $userName | tr 'A-Z' 'a-z')
userdel $userName
rm -rf /home/$userName
echo "Successfully deleted user $userName"
done
fi
Link:
Thx!
Hey all,
We need to setup a squid-proxy for a hotel, and we need to do some automation on the users administration. For this we have created a solution based on a bash script and the NCSA authentication system.
The script that we use to insert users that will be able to navigate via proxy inserts the usernames in the /etc/squid/htpasswd file and creates a second csv file described below:
prova1.prova1,1273781005
prova2.prova2,1273781016
prova3.prova3,1273781035
Where:
the first field is username composed by firstname.lastname,
the second field number is the timestamp in which users must be deleted
What I need is one or two scripts (Your advice here would be helpful) in order to:
1. grep all user's that have a minor timestamp than now (date --date="now" +%s).
2. delete those users using the htpasswd system and command which is:
htpasswd -D /etc/squid/passwd username
Anyone could help me?
Here's a script that I tried to adapt but couldn't make it because of lack of bash knowledge:
Delete User Script
#!/bin/bash
echo "Assignment1"
if [ "$(whoami)" != "root" ]
then
echo "Error: You ARE NOT ROOT!!!!!"
exit 1
else
echo "You are Lucky! I am watching you!!"
echo "Please enter the CSV"
read CSVFILE
exec < $CSVFILE
while
read line
do
firstName=$(echo $line | awk -F, '{print $1'})
lastName=$(echo $line | awk -F, '{print $2'})
idNumber=$(echo $line | awk -F, '{print $3'})
firstInit=$(echo $line | cut -c1)
userName=$lastName$firstInit
userName=$(echo $userName | tr 'A-Z' 'a-z')
userdel $userName
rm -rf /home/$userName
echo "Successfully deleted user $userName"
done
fi
Link:
Thx!