Linux Reboot/Shutdown using PB app

Linux specific forum
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Linux Reboot/Shutdown using PB app

Post by swhite »

Hi
I would like to be able to have my Purebasic application reboot or shutdown a Linux PC. A number of the commands to accomplish this require root privileges. However RunProgram does not have the ability to specify a user and password. Does anyone have a suggestion about how this might be accomplished? I am running on OpenSuse 15.3 and PB 5.73.

Thanks,
Simon
Simon White
dCipher Computing
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linux Reboot/Shutdown using PB app

Post by mk-soft »

Perhaps help ...

Link: viewtopic.php?f=12&t=71693
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Linux Reboot/Shutdown using PB app

Post by infratec »

You can also use sudo with RunProgram()
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: Linux Reboot/Shutdown using PB app

Post by swhite »

Hi

How exactly do you use sudo with RunProgram given that sudo needs a password?

Thanks,
Simon
Simon White
dCipher Computing
User avatar
useful
Enthusiast
Enthusiast
Posts: 363
Joined: Fri Jul 19, 2013 7:36 am

Re: Linux Reboot/Shutdown using PB app

Post by useful »

Dawn will come inevitably.
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linux Reboot/Shutdown using PB app

Post by mk-soft »

Part from RunAsAdmin and modified ...

not testet ...

Code: Select all


Procedure SuDo(user.s, passwd.s, program.s)
  Protected cmd.s
  
  If user = UserName()
    cmd.s = "-c " + #DQUOTE$ + "echo " + passwd + " | sudo -S " + program + #DQUOTE$
  Else
    cmd.s = "-c " + #DQUOTE$ + "echo " + passwd + " | sudo -u " + user + " -S " + program + #DQUOTE$
  EndIf
  If RunProgram("bash", cmd, "")
    ; 
  Else
    MessageRequester("Error", "Execute With Privileges!", #PB_MessageRequester_Error)
  EndIf
  
EndProcedure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: Linux Reboot/Shutdown using PB app

Post by swhite »

Thanks for these useful examples. I will give them a try.

Simon
Simon White
dCipher Computing
Post Reply