1,105,644 Community Members

validation before removing user

Member Avatar
Rizzuti
Newbie Poster
15 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I'm trying to check if the user that im deleting exist in the database before deleting them, but it does not recognise the id (delID) the second time that i enter the id (even if it is right).

Any suggestion

delete(){
clear
echo "-------------"
echo "DELETE RECORDS"
echo "-------------"
read -p "Please enter staff id that you wish to delete: " delID

indelID=$(grep $delID ~/appraisal/work.db | cut -d":" -f1)
surname=$(grep $delID ~/appraisal/work.db | cut -d":" -f2)
name=$(grep $delID ~/appraisal/work.db | cut -d":" -f3)

while [[ "$(echo $delID | grep -c '^[0-9][0-9][0-9]$')" = 0 || $delID = $inlID ]]
do
read -p "The staff ID entered is incorrect, please try again: " delID
done
echo "Would you like to delete $name $surname from the database? (press y or n)"
read ans

if [[ $ans = y* || $ans = Y* ]]
then
sed -i "/$delID/d" ~/appraisal/work.db
echo "record deleted!"
else [$ans != n ]
menu
fi
read -p "Press return access the main menu " main
menu
}

Thanks

Member Avatar
Pjieter
Junior Poster
114 posts since Jan 2012
Reputation Points: -8 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
-1
 

@Rizzuti:
You tried running the file as root?

sudo script
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: