script with admin privileges

File delete_media.sh

# You need to give password for USER <USERNAME>

echo "Please Enter the password for USER `tput smso`<USERNAME>`tput rmso`"

su - <USERNAME> -c "sh bin/del_media_dir.sh"

 

File dell_media_dir.sh

#!/bin/sh +xv

# set +xv
echo "\n\n\nThis is the Program to remove EXTERNAL HARD DISK DRIVES(e.g. USB, HDD, etc.) :\nProgram is : [`tput smso`{ $0 }`tput rmso`] :\n\n"

# echo $* 
# echo $1

cd /media
echo "Current Directory is : [`tput smso`{ `pwd` }`tput rmso`] :"
# pwd

echo -n "\nExisting files in above Directory are : [`tput smso`{ "
echo -n `ls`
echo " }`tput rmso`] :\n\n\n"


for i in `ls`
do
echo " `tput smso`{ ${i} }`tput rmso`\n\n"


echo "Do you want to delete `tput smso`${i}`tput rmso`"
read ans

# echo ${ans}
ans=`echo ${ans} | tr [:upper:] [:lower:]`
# echo "ANS ${ans} after proper"
echo "ANS :`tput smso` ${ans}`tput rmso`"

# set -xv

if [ "${ans}" = "y" ]
then
    echo "\nYes:\nI am going to delete Directory : \t `tput smso`{ /media/${i} }`tput rmso`\n\n\n"

##### Add following lines in /etc/sudoers so "sudo /bin/rmdir functions as intended"
##### <USERNAME> ALL=(ALL) NOPASSWD: /bin/rmdir
    sudo /bin/rmdir /media/${i}
fi

sleep 3
done


echo "Please press Enter"
read Enter
sleep 11


cd -
# pwd

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s