Root cron executing command from a different user account


#1

I dont have to do this often and it always trips me. Should be trivial, but I cant remember what the issue is.

I update the example to something simpler:
Please consider this first

          • DISPLAY=:0 /bin/su - $usernamenotroot -c $(xterm -hold -e whoami)
            #Where $usernamenotroot is an arbitrary user on the system except root you want to display the message to, in an xterm from this cron entry running in root.
            Whoami must obviously display the user’s name in the terminal. That is unfortunately not what happens. Obviously I will alter the Display number for every user, but lets stick to 0 for the example.

Anyone knows how to solve this, as I think I will solve the rest of my problems if I get a solution to this.


#2

You could replace the whoami program with a script that writes the $usernamenotroot in place of whoami…
It really depends on what you are really trying to do…


#3

No, the point of this is to display an xterm on a users account with some text in it from a ROOT cronjob. The xterm of course must be a user account xterm and not a root xterm.

If this works then it will solve my other issues.


#4

It is bit complicated to show GUI message from cron. I posted one solution:


#5

Thanks Nixcraft, I will try what you propose.