linux - Run scipt like sudo with Gksudo -
I'm new in linux I'm trying to mount and umount. ISO with nano script I put the script /home/user/.gnome2/nemo-scripts/
. My problem is, with gksudo I run su command like only 1. How do I run this script?
#! / Bin / bash gksudo -k / bin / echo "got r00t?" BNAME = $ (basename "$ NEMO_SCRIPT_SELECTED_FILE_PATHS") sudo mkdir "/ Media / $ BNAME" --info --title "ISO Mounter" zenity if sudo is ISO9660 $ Income Tax - o loop mount --text "$ BNAME e $ NEMO_SCRIPT_SELECTED_FILE_PATHS" NEMO_SCRIPT_SELECTED_FILE_PATHS "/ Media / $ BNAME" if zenity --question --title "ISO Mounter" --text "$ BNAME successfully mounted. Open Volume?" Then the Nemo / Media / $ BNAME --no- the rest of the desktop fi exit 0 sudo rmdir "/ media / $ bname" zenity --error --title "ISO mounter" --text "$ can not be mounted BNAME! "
There are a couple of ways to do this in your script above, you root You can execute the full script with permission
if you call the script only with the su -c script
or sudo script
. Before doing this, edit your script and remove the call at gksudo
and sudo
. Then adding a test to insure the script at the top of your script is run with an effective root UID. Ex:
#! / Bin / bash if test "$ UID" -ec 0; So run the script as "printf" root \ n "other printf" error, this script can only be run by root \ n "exit 1; Fi
Then make sure that you run your script as sudo scriptname
or su -c scriptname
. Additionally, Make sure that you have an executed bit set of your script file permissions You will simply give this chmod 0775 SCRIPTNAME script
which you can do with owner < / Code> and groups
read-write-executed permissions and read-execute world
permissions. If you do not want it to be world executable, just click chmod 0774
.
If you do not set permission for execution on your script , you can not get a permission denied
or order
Get the error You can execute the script by specifying the shell in your sudo
or su
call, e.g. sudo bash SCRIPTNAME script
or su -c "Bash SCRIPTNAME script"
, but this script is preferred to make it executable.
Comments
Post a Comment