I'm working on a script for user Bob with the relevant parts shown below. Problem I'm having is if I put this cronjob under user Bob, zenity will work but shutdown wont. And if I put it under root shutdown will work but zenity won't be visible on console.

eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u Bob gnome-session)/environ)";
someValue=`DISPLAY=:0.0 zenity --text="tell me your value" --entry`
/sbin/shutdown -h "now"

I also tried running under root and using su to Bob for zenity and exiting back to root to shutdown, but that didn't work.

Is there a way to do this?

Other info

OS is Linux Mint and Bob is the only user of the machine


Non-privileged users cannot shutdown a machine from command line. If you absolutely need to send shutdown as Bob, you can add him to sudoers using visudo.

sudo visudo

Add the following line to is:

bob ALL = (root) NOPASSWD: /sbin/shutdown -h "now"

Save file. Then you can su as bob and test the command:

sudo /sbin/shutdown -h "now"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.