Find the answer to your Linux question:
Results 1 to 5 of 5
Hello people, i'm new to this linux business and i really need your help. I'm running ubuntu 7.04 I need to run a script that will be executed in cron. ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    13

    Exclamation run command as root from shell script

    Hello people, i'm new to this linux business and i really need your help.
    I'm running ubuntu 7.04
    I need to run a script that will be executed in cron.
    This script must shutdown the linux box.
    The problem i have is that i can't run the shutdown because i don't have root permissions in this user.
    I don't want to modify my user's permissions, i just want to enter a script with the username and password of root that turns off the linux box
    thanks a lot

  2. #2
    Linux Guru Juan Pablo's Avatar
    Join Date
    Mar 2006
    Location
    /home/south_america/ecuador/quito
    Posts
    2,064
    I'm afraid it's not possible to just 'store' in a file the root password, it's not a good idea either. The best I can think of is using a password-less sudo that just works for shutdown
    Put your hand in an oven for a minute and it will be like an hour, sit beside a beautiful woman for an hour and it will be like a minute, that is relativity. --Albert Einstein
    Linux User #425940

    Don't PM me with questions, instead post in the forums

  3. #3
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    As another option, see this blurb from the manpages for shutdown(8 )
    (in code tags to preserve formatting):
    Code:
    ACCESS CONTROL
           shutdown  can  be called from init(8) when the magic keys CTRL-ALT-DEL
           are pressed, by creating an appropriate entry  in  /etc/inittab.  This
           means  that  everyone  who has physical access to the console keyboard
           can shut the system down. To prevent this, shutdown can check  to  see
           if  an authorized user is logged in on one of the virtual consoles. If
           shutdown is called with the -a argument (add this to the invocation of
           shutdown  in  /etc/inittab),  it  checks to see if the file /etc/shut-
           down.allow is present.  It then compares the login names in that  file
           with  the list of people that are logged in on a virtual console (from
           /var/run/utmp). Only if one of  those  authorized  users  or  root  is
           logged in, it will proceed. Otherwise it will write the message
    
           shutdown: no authorized users logged in
    
           to the (physical) system console. The format of /etc/shutdown.allow is
           one user name per line. Empty lines and comment lines (prefixed  by  a
           #) are allowed. Currently there is a limit of 32 users in this file.
    
           Note  that  if  /etc/shutdown.allow is not present, the -a argument is
           ignored.
    So with some modifications to /etc/inittab and additions to /etc/shutdown.allow you may be able to produce the functionality you want.

    Caveat: This is a CentOS 4.5 box. You'll need to check if the same rules apply for your ubuntu box.

  4. #4
    Just Joined!
    Join Date
    Jun 2007
    Posts
    13
    thanks people for your help, you are the very best linux has to offer.
    I think the linux software rocks but the comunity of users, experienced users and programmers that are willingly helping each other is the real linux spirit and POWER.
    Im gonna tell you how i´ve solved this problem of mine. (this probably is a way to stupid way to do it but is the one that is working now for me)
    I just made a crontab file for the user root which im certain that has shutdown permissions.
    1- open terminal
    2- log as root (su)
    3- crontab -u root -e
    4- 15 15 * * * /sbin/shutdown -r now
    minute hour dom dow command to execute.
    Now your computer will automatically shut down every day at 15:15 hours.

    It works like a charm in ubuntu linux 7.04 feisty feast 64 bit edition

    HOPE THIS HELPS SOMEONE.
    THANKS A LOT FOR YOUR HELP

    Pd: do you know any firewall out of the box for linux (with gui and ms windows like stuff like kerio for example) im new to linux i was a pretty good windows user

  5. #5
    Linux Guru Juan Pablo's Avatar
    Join Date
    Mar 2006
    Location
    /home/south_america/ecuador/quito
    Posts
    2,064
    Try firestarter, it's a frontend to IPtables, the default Linux firewall
    Put your hand in an oven for a minute and it will be like an hour, sit beside a beautiful woman for an hour and it will be like a minute, that is relativity. --Albert Einstein
    Linux User #425940

    Don't PM me with questions, instead post in the forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...