I\'ve made a simple bash script that need to keep it\'s super-user privileges throughout the script. Unfortunately, but understandable the script looses its sudo
This my way:
#!/bin/sh
echo "Working..."
# add you pass
echo "yourpass" >> file.pass ;sleep 5
# Check if root
if [ `cat file.pass | sudo -S su root -c whoami` != "root" ]; then
echo "Not running as root. Exiting..."
sleep 2
echo "Cleaning..."
sleep 1
srm file.pass
echo "Cleaned"
exit 0
else
echo "Running as root. Good"
sleep 2
# and run any sudo with
cat file.pass | sudo -S su root -c ls #
fi
sleep 5
echo `cat file.pass | sudo -S su root -c whoami` "say bay bay"
# if pass no longer need
srm file.pass
echo "End session :)"
exit 0