Announcement

Collapse
No announcement yet.

How to run a script that needs root permissions?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to run a script that needs root permissions?

    Hi,

    I would like to make a script to update the clock of my Linux distro (Kubuntu), using ntpdate.
    But ntpdate needs root permissions. From the command line, I can use "sudo ntpdate ..." and then give my password, but how can this be done from a script?

    Best rgds,

    --Geert

    #2
    Re: How to running a script that needs root permissions?

    Im not 100% sure, but i think that if you run the script with root permissions, that access level elevation applies to every line of the entire script.

    so say you had script.sh

    and script.sh contained:

    Code:
    ls
    ntpdate
    and you executed it like this,

    Code:
    sh script.sh
    it would execute the ls, and then throw an error about needing root permissions for ntpdate.

    hoewere if you initiated the script with
    Code:
    sudo script.sh
    then it should execute the ntpdate fine, due to the access levels for the script in general being elevated to root.

    Comment


      #3
      Re: How to run a script that needs root permissions?

      Originally posted by f1rem0th
      hoewere if you initiated the script with
      Code:
      sudo script.sh
      then it should execute the ntpdate fine, due to the access levels for the script in general being elevated to root.
      Indeed, that does the trick!

      Thanks very much.

      Best rgds,

      --Geert

      Comment


        #4
        Re: How to running a script that needs root permissions?



        About ntpdate:

        Time is accelerating in KDE
        http://kubuntuforums.net/forums/index.php?topic=8116.0
        Before you edit, BACKUP !

        Why there are dead links ?
        1. Thread: Please explain how to access old kubuntu forum posts
        2. Thread: Lost Information

        Comment


          #5
          Re: How to run a script that needs root permissions?

          Originally posted by Rog131


          About ntpdate:

          Time is accelerating in KDE
          http://kubuntuforums.net/forums/index.php?topic=8116.0
          That is even better, since I can let the system update the clock automatically.

          Was completely not aware of the existence of KCron... Should play more with the GUI iso working too much command line...

          Tnx!

          Best rgds,

          --Geert

          Comment


            #6
            Re: How to running a script that needs root permissions?



            Sometimes "passwordless sudo for the script" is handy:

            Topic: Need some help with shell scripts.
            http://kubuntuforums.net/forums/index.php?topic=5493.0

            Be careful !


            Links:
            Sudoers
            https://help.ubuntu.com/community/Sudoers

            Sudoers Manual
            http://www.gratisoft.us/sudo/man/sudoers.html

            How to configure Sudo to run programs as a different user
            http://newbiedoc.berlios.de/wiki/How...different_user
            Before you edit, BACKUP !

            Why there are dead links ?
            1. Thread: Please explain how to access old kubuntu forum posts
            2. Thread: Lost Information

            Comment

            Working...
            X