LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-30-2016, 08:43 PM   #1
yoda2016
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Rep: Reputation: Disabled
Scripting help


Hi all iv'e been messing around with scripting a shutdown script for a couple of weeks i just need a helping hand with a few things, the script is complete but i need to wright a separate script that will copy the shutdown script to /usr/bin, and create a shortcut in the applications menu.

from what i know only the root user can write to /usr/bin

The shutdown script runs in a terminal and i access the script by clicking the icon on my desktop and the terminal starts and runs my shutdwon script

i have a friend who wants to try my script and he is still learning Linux so it would help if it could be done

,Yoda
 
Old 11-30-2016, 10:39 PM   #2
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Don't write anything to /usr/bin. Unless you want your setup to end up in quite a mess. If you really want to write to $PATH, you can use your own $HOME/bin for that.
 
Old 12-01-2016, 02:00 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,536
Blog Entries: 3

Rep: Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398Reputation: 3398
Some finished scripts can go in /usr/local/bin/ or /usr/local/sbin/ depending on their nature. See man 7 hier for details. But for works in progress or something local to one single user, then $HOME/bin/ is usually best. especially if you don't need to prevent write access. If you don't have $HOME/bin/ already just create it and start adding your scripts. It will be available in your $PATH automatically (on most distros) the next time you log in.
 
Old 12-01-2016, 09:23 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 25,391

Rep: Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568
Quote:
Originally Posted by yoda2016 View Post
Hi all iv'e been messing around with scripting a shutdown script for a couple of weeks i just need a helping hand with a few things, the script is complete but i need to wright a separate script that will copy the shutdown script to /usr/bin, and create a shortcut in the applications menu.

from what i know only the root user can write to /usr/bin

The shutdown script runs in a terminal and i access the script by clicking the icon on my desktop and the terminal starts and runs my shutdwon script i have a friend who wants to try my script and he is still learning Linux so it would help if it could be done
Ok...so can you post what you've written/done/tried so far, and tell us where you're stuck?
 
Old 12-01-2016, 10:27 AM   #5
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,937

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Normally, a script would be run with user permissions.
It is relatively easy to cause a script to run as the owner of the script.

So you just change the owner to 'root' and allow anyone to run the script.
This has severe security implications!

Investigate 'setuid' if you are willing to take the risks.
 
Old 12-01-2016, 02:22 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,731
Blog Entries: 13

Rep: Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784
A recommendation is to post your script within [code][/code] tags, or using the # tool in advanced edit mode on the LQ site.

There are some links in my signature related to BASH programming as well as a blog I've written to aid with debugging scripts.

It's difficult for us to offer any assistance when we have no idea what you're doing. Immediate feedback would be any of:
Code:
$shutdown -h now
Or the alternate:
Code:
$poweroff
But my assumption is that you're trying to do other things. Also note that mounted file systems will be closed and un-mounted during a normal shutdown. What you may be doing is trying to detect certain processes running and shutting them down differently than a system shutdown would do. However it will be helpful to know if you're being redundant with the system's intentions.
 
Old 12-01-2016, 04:36 PM   #7
yoda2016
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks for your advice, all i need is a script to copy my script to the $home/bin folder, and have an icon created for the applications menu.

what i'm trying to achieve is this.
  • Give my friend my script in an archive
  • Friend extracts contents of archive
  • friend runs the install script
  • my script is copied to $home/bin
  • an icon is added to the applications menu

my completed script (may make some revisions down the line)
Code:
#!/bin/bash
# a simple shutdown script
# Cosmetic crap nothing realy important but it does demenstrate how an "here document: ie <<"EOF" EOF Handy isent it
cat << "EOF"                                                                                                                                      
o       O            o        Oo      
O       o           O         oO      
`o     O'           o          O      
  O   o             o         o'      
   `O'    .oOo. .oOoO  .oOoO'    .oOo 
    o     O   o o   O  O   o     `Ooo.
    O     o   O O   o  o   O         O
    O     `OoO' `OoO'o `OoO'o    `OoO'                                                                                                                                                                                                     


.oOOOo.   o                      o                      
o     o  O                      O                       
O.       o              O       o                       
 `OOoo.  O             oOo      o                       
      `O OoOo. O   o    o   .oOoO  .oOo. 'o     O 'OoOo.
       o o   o o   O    O   o   O  O   o  O  o  o  o   O
O.    .O o   O O   o    o   O   o  o   O  o  O  O  O   o
 `oooO'  O   o `OoO'o   `oO `OoO'o `OoO'  `Oo'oO'  o   O
                                                        

oOoOOoOOo                         
    o     o                       
    o                             
    O                             
    o     O  `oOOoOO. .oOo. `OoOo.
    O     o   O  o  o OooO'  o    
    O     O   o  O  O O      O    
    o'    o'  O  o  o `OoO'  o    
EOF

# This part asks for the time in mins untill user requested shutdown
echo
echo
read -p 'Time to Shutdown in Mins: ' tvar
echo
# the complete terminal command using the variable set by the user at script run
shutdown -h $tvar
echo
echo Thank You For using Yoda\'s Shutdown Timer
echo
,Yoda
 
Old 12-02-2016, 08:16 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 10,045

Rep: Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158
Quote:
Originally Posted by yoda2016 View Post
Thanks for your advice, all i need is a script to copy my script to the $home/bin folder, and have an icon created for the applications menu.

what i'm trying to achieve is this.
  • Give my friend my script in an archive
  • Friend extracts contents of archive
  • friend runs the install script
  • my script is copied to $home/bin
  • an icon is added to the applications menu

,Yoda

Code:
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk
import os
import getpass

dbus_send = "dbus-send --print-reply --system --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.{} boolean:true"

class bl_exit:
    def disable_buttons(self):
        self.cancel.set_sensitive(False)
        self.logout.set_sensitive(False)
        self.suspend.set_sensitive(False)
        self.reboot.set_sensitive(False)
        self.shutdown.set_sensitive(False)

    def cancel_action(self,btn):
        self.disable_buttons()
        gtk.main_quit()

    def logout_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Exiting Openbox, please standby...")
        os.system("openbox --exit")

    def suspend_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Suspending, please standby...")
        os.system("bl-lock")
        os.system(dbus_send.format("Suspend"))
        gtk.main_quit()

    def reboot_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Rebooting, please standby...")
        os.system(dbus_send.format("Reboot"))

    def shutdown_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Shutting down, please standby...")
        os.system(dbus_send.format("PowerOff"))

    def create_window(self):
        self.window = gtk.Window()
        title = "Log out " + getpass.getuser() + "? Choose an option:"
        self.window.set_title(title)
        self.window.set_border_width(5)
        self.window.set_size_request(500, 80)
        self.window.set_resizable(False)
        self.window.set_keep_above(True)
        self.window.stick
        self.window.set_position(1)
        self.window.connect("delete_event", gtk.main_quit)
        windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
        self.window.set_icon(windowicon)


        #Create HBox for buttons
        self.button_box = gtk.HBox()
        self.button_box.show()

        #Cancel button
        self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
        self.cancel.set_border_width(4)
        self.cancel.connect("clicked", self.cancel_action)
        self.button_box.pack_start(self.cancel)
        self.cancel.show()

        #Cancel key (Escape)
        accelgroup = gtk.AccelGroup()
        self.key, self.mod = gtk.accelerator_parse('Escape')
        accelgroup.connect_group(self.key, self.mod, gtk.ACCEL_VISIBLE, gtk.main_quit)
        self.window.add_accel_group(accelgroup)

        #Logout button
        self.logout = gtk.Button("_Log out")
        self.logout.set_border_width(4)
        self.logout.connect("clicked", self.logout_action)
        self.button_box.pack_start(self.logout)
        self.logout.show()

        #Suspend button
        self.suspend = gtk.Button("_Suspend")
        self.suspend.set_border_width(4)
        self.suspend.connect("clicked", self.suspend_action)
        self.button_box.pack_start(self.suspend)
        self.suspend.show()

        #Reboot button
        self.reboot = gtk.Button("_Reboot")
        self.reboot.set_border_width(4)
        self.reboot.connect("clicked", self.reboot_action)
        self.button_box.pack_start(self.reboot)
        self.reboot.show()

        #Shutdown button
        self.shutdown = gtk.Button("_Power off")
        self.shutdown.set_border_width(4)
        self.shutdown.connect("clicked", self.shutdown_action)
        self.button_box.pack_start(self.shutdown)
        self.shutdown.show()

        #Create HBox for status label
        self.label_box = gtk.HBox()
        self.label_box.show()
        self.status = gtk.Label()
        self.status.show()
        self.label_box.pack_start(self.status)

        #Create VBox and pack the above HBox's
        self.vbox = gtk.VBox()
        self.vbox.pack_start(self.button_box)
        self.vbox.pack_start(self.label_box)
        self.vbox.show()

        self.window.add(self.vbox)
        self.window.show()

    def __init__(self):
        self.create_window()


def main():
    gtk.main()

if __name__ == "__main__":
    go = bl_exit()
    main()
but I do not remember if this one is pre systemD or post systemD compatible.

you still need root permissions to call shut down , reboot, halt commands . doing this in a bash script. you need to research .. how to call for root login in bash before it can even make a valid shutdown, reboot, halt. polkit-1 settings for example -- need to be modified.

for logout that is a different story.

Last edited by BW-userx; 12-02-2016 at 08:25 PM.
 
Old 12-02-2016, 08:39 PM   #9
yoda2016
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
Code:
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk
import os
import getpass

dbus_send = "dbus-send --print-reply --system --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.{} boolean:true"

class bl_exit:
    def disable_buttons(self):
        self.cancel.set_sensitive(False)
        self.logout.set_sensitive(False)
        self.suspend.set_sensitive(False)
        self.reboot.set_sensitive(False)
        self.shutdown.set_sensitive(False)

    def cancel_action(self,btn):
        self.disable_buttons()
        gtk.main_quit()

    def logout_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Exiting Openbox, please standby...")
        os.system("openbox --exit")

    def suspend_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Suspending, please standby...")
        os.system("bl-lock")
        os.system(dbus_send.format("Suspend"))
        gtk.main_quit()

    def reboot_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Rebooting, please standby...")
        os.system(dbus_send.format("Reboot"))

    def shutdown_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Shutting down, please standby...")
        os.system(dbus_send.format("PowerOff"))

    def create_window(self):
        self.window = gtk.Window()
        title = "Log out " + getpass.getuser() + "? Choose an option:"
        self.window.set_title(title)
        self.window.set_border_width(5)
        self.window.set_size_request(500, 80)
        self.window.set_resizable(False)
        self.window.set_keep_above(True)
        self.window.stick
        self.window.set_position(1)
        self.window.connect("delete_event", gtk.main_quit)
        windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
        self.window.set_icon(windowicon)


        #Create HBox for buttons
        self.button_box = gtk.HBox()
        self.button_box.show()

        #Cancel button
        self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
        self.cancel.set_border_width(4)
        self.cancel.connect("clicked", self.cancel_action)
        self.button_box.pack_start(self.cancel)
        self.cancel.show()

        #Cancel key (Escape)
        accelgroup = gtk.AccelGroup()
        self.key, self.mod = gtk.accelerator_parse('Escape')
        accelgroup.connect_group(self.key, self.mod, gtk.ACCEL_VISIBLE, gtk.main_quit)
        self.window.add_accel_group(accelgroup)

        #Logout button
        self.logout = gtk.Button("_Log out")
        self.logout.set_border_width(4)
        self.logout.connect("clicked", self.logout_action)
        self.button_box.pack_start(self.logout)
        self.logout.show()

        #Suspend button
        self.suspend = gtk.Button("_Suspend")
        self.suspend.set_border_width(4)
        self.suspend.connect("clicked", self.suspend_action)
        self.button_box.pack_start(self.suspend)
        self.suspend.show()

        #Reboot button
        self.reboot = gtk.Button("_Reboot")
        self.reboot.set_border_width(4)
        self.reboot.connect("clicked", self.reboot_action)
        self.button_box.pack_start(self.reboot)
        self.reboot.show()

        #Shutdown button
        self.shutdown = gtk.Button("_Power off")
        self.shutdown.set_border_width(4)
        self.shutdown.connect("clicked", self.shutdown_action)
        self.button_box.pack_start(self.shutdown)
        self.shutdown.show()

        #Create HBox for status label
        self.label_box = gtk.HBox()
        self.label_box.show()
        self.status = gtk.Label()
        self.status.show()
        self.label_box.pack_start(self.status)

        #Create VBox and pack the above HBox's
        self.vbox = gtk.VBox()
        self.vbox.pack_start(self.button_box)
        self.vbox.pack_start(self.label_box)
        self.vbox.show()

        self.window.add(self.vbox)
        self.window.show()

    def __init__(self):
        self.create_window()


def main():
    gtk.main()

if __name__ == "__main__":
    go = bl_exit()
    main()
but I do not remember if this one is pre systemD or post systemD compatible.

you still need root permissions to call shut down , reboot, halt commands . doing this in a bash script. you need to research .. how to call for root login in bash before it can even make a valid shutdown, reboot, halt. polkit-1 settings for example -- need to be modified.

for logout that is a different story.
when i am logged in as a normal user i can use the script and it will shutdown the system.

can you test the script to see if its a fluke of nature or something that fedora have done to thier distros. if it doesnt work ill look into doing this another way via another style of application but will need to figure out which language would be best for the task if you can test the script could offer me some pointers to make it more user friendly
 
Old 12-02-2016, 09:16 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 10,045

Rep: Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158
Quote:
Originally Posted by yoda2016 View Post
when i am logged in as a normal user i can use the script and it will shutdown the system.

can you test the script to see if its a fluke of nature or something that fedora have done to thier distros. if it doesnt work ill look into doing this another way via another style of application but will need to figure out which language would be best for the task if you can test the script could offer me some pointers to make it more user friendly
give yourself sudo ?

Code:
#!/bin/bash
#for root rights with sudo

sudo command
sudo command
yeah sure when I shut down ,,

Code:
userx@voided1.what~>> ./shutme


Time to Shutdown in Mins: 1

Script started, file is run
still waiting... hold on
not my system, no go


Code:
userx@voided1.what~>> man shutdown > shutyou

userx@voided1.what~>> cat shutyou
SHUTDOWN(8)                 System Manager's Manual                SHUTDOWN(8)

NAME
     shutdown – bring down the system

SYNOPSIS
     shutdown [-rhP] [-fF] [now | +mins] [message ...]

DESCRIPTION
     shutdown brings the system down in a secure way.  All logged-in users are
     notified that the system is going down, and login(1) is blocked.

     By default, shutdown puts the system into single user mode.  Rebooting
     and halting the system can be done using the following options:

     -c      Cancel an ongoing shutdown.

     -f      Enable fast booting; skip fsck(8) on next boot.

     -F      Force run of fsck(8) on next boot.

     -h      Halt the system.

     -k      Don't really shutdown; only send the warning messages to
             everybody.

     -P      Poweroff the system.

     -r      Reboot the system.

     now     Shutdown without further waiting.

     +mins   Wait mins minutes before shutting down.

     message
             Message displayed to all users, defaults to "system is going
             down".

UNSUPPORTED OPTIONS
     This version of shutdown is based on runit(8), the following features are
     not supported:

     -t secs
             to wait secs seconds between SIGKILL and SIGTERM on shutdown is
             silently ignored.

     -a      Use /etc/shutdown.allow.

     -H      Drop into boot monitor.

     -n      Don't call init(8).

     hh:mm   Absolute time specification is not implemented.

EXAMPLES
     Turn off the system:
           # shutdown -h now

SEE ALSO
     fsck(8), halt(8), init(8), poweroff(8), reboot(8), runit(8),
     runsvchdir(8)

AUTHOR
     Christian Neukirchen, chneukirchen@gmail.com.

Linux                            July 29, 2014                           Linux
Code:
userx@voided1.what~>> shutdown -h 1
Not enough permissions to execute usr/bin/shutdown
Code:
userx@voided1.what~>> sudo shutdown -h 1
invalid time
Code:
userx@voided1.what~>> shutdown -h -t 10
Usage: shutdown [-fF] [-kchPr] time [warning message]
Code:
userx@voided1.what~>> shutdown -h -t 10
Usage: shutdown [-fF] [-kchPr] time [warning message]
userx@voided1.what~>> shutdown -h 1
Not enough permissions to execute usr/bin/shutdown
userx@voided1.what~>> sudo shutdown -h 1
invalid time
userx@voided1.what~>> sudo shutdown -h time 1
invalid time
userx@voided1.what~>> sudo shutdown time 1
invalid time
userx@voided1.what~>> sudo shutdown time 10
invalid time
userx@voided1.what~>> sudo shutdown -h 2
invalid time
userx@voided1.what~>> sudo shutdown -h 3
invalid time
userx@voided1.what~>> sudo shutdown -h 4
invalid time
userx@voided1.what~>> sudo shutdown -h 5
invalid time
userx@voided1.what~>> sudo shutdown 5
invalid time
userx@voided1.what~>> sudo shutdown -h 1:00
absolute time is not implemented
Personally I just use halt on my command line


OK Here is what I got for my system on the command line
Code:
shutdown -f -h +mins 3
that equates to 3 seconds
I am sure you can turn that into BASH code.

http://linux.101hacks.com/unix/shutdown/

it is late right now tomorrow I'll give it a look through to see if you can make it more everybody user friendly, remember person has to have sudo , call sudo in the script too will work, you can give and ask for more info, error checking too can be added.

Last edited by BW-userx; 12-02-2016 at 10:12 PM.
 
Old 12-03-2016, 06:11 PM   #11
yoda2016
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
give yourself sudo ?

Code:
#!/bin/bash
#for root rights with sudo

sudo command
sudo command
yeah sure when I shut down ,,

Code:
userx@voided1.what~>> ./shutme


Time to Shutdown in Mins: 1

Script started, file is run
still waiting... hold on
not my system, no go


Code:
userx@voided1.what~>> man shutdown > shutyou

userx@voided1.what~>> cat shutyou
SHUTDOWN(8)                 System Manager's Manual                SHUTDOWN(8)

NAME
     shutdown  bring down the system

SYNOPSIS
     shutdown [-rhP] [-fF] [now | +mins] [message ...]

DESCRIPTION
     shutdown brings the system down in a secure way.  All logged-in users are
     notified that the system is going down, and login(1) is blocked.

     By default, shutdown puts the system into single user mode.  Rebooting
     and halting the system can be done using the following options:

     -c      Cancel an ongoing shutdown.

     -f      Enable fast booting; skip fsck(8) on next boot.

     -F      Force run of fsck(8) on next boot.

     -h      Halt the system.

     -k      Don't really shutdown; only send the warning messages to
             everybody.

     -P      Poweroff the system.

     -r      Reboot the system.

     now     Shutdown without further waiting.

     +mins   Wait mins minutes before shutting down.

     message
             Message displayed to all users, defaults to "system is going
             down".

UNSUPPORTED OPTIONS
     This version of shutdown is based on runit(8), the following features are
     not supported:

     -t secs
             to wait secs seconds between SIGKILL and SIGTERM on shutdown is
             silently ignored.

     -a      Use /etc/shutdown.allow.

     -H      Drop into boot monitor.

     -n      Don't call init(8).

     hh:mm   Absolute time specification is not implemented.

EXAMPLES
     Turn off the system:
           # shutdown -h now

SEE ALSO
     fsck(8), halt(8), init(8), poweroff(8), reboot(8), runit(8),
     runsvchdir(8)

AUTHOR
     Christian Neukirchen, chneukirchen@gmail.com.

Linux                            July 29, 2014                           Linux
Code:
userx@voided1.what~>> shutdown -h 1
Not enough permissions to execute usr/bin/shutdown
Code:
userx@voided1.what~>> sudo shutdown -h 1
invalid time
Code:
userx@voided1.what~>> shutdown -h -t 10
Usage: shutdown [-fF] [-kchPr] time [warning message]
Code:
userx@voided1.what~>> shutdown -h -t 10
Usage: shutdown [-fF] [-kchPr] time [warning message]
userx@voided1.what~>> shutdown -h 1
Not enough permissions to execute usr/bin/shutdown
userx@voided1.what~>> sudo shutdown -h 1
invalid time
userx@voided1.what~>> sudo shutdown -h time 1
invalid time
userx@voided1.what~>> sudo shutdown time 1
invalid time
userx@voided1.what~>> sudo shutdown time 10
invalid time
userx@voided1.what~>> sudo shutdown -h 2
invalid time
userx@voided1.what~>> sudo shutdown -h 3
invalid time
userx@voided1.what~>> sudo shutdown -h 4
invalid time
userx@voided1.what~>> sudo shutdown -h 5
invalid time
userx@voided1.what~>> sudo shutdown 5
invalid time
userx@voided1.what~>> sudo shutdown -h 1:00
absolute time is not implemented
Personally I just use halt on my command line


OK Here is what I got for my system on the command line
Code:
shutdown -f -h +mins 3
that equates to 3 seconds
I am sure you can turn that into BASH code.

http://linux.101hacks.com/unix/shutdown/

it is late right now tomorrow I'll give it a look through to see if you can make it more everybody user friendly, remember person has to have sudo , call sudo in the script too will work, you can give and ask for more info, error checking too can be added.
no sudo in use that im aware of, could it be when i set my machine up i gave a root password, then set up my user profile as administrator, just trying to iron out any problems for future referance
 
Old 12-03-2016, 06:52 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 10,045

Rep: Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158
Quote:
Originally Posted by yoda2016 View Post
no sudo in use that im aware of, could it be when i set my machine up i gave a root password, then set up my user profile as administrator, just trying to iron out any problems for future reference
seeings how one has to have, or is suppose to have, as in your system. It seems to be working without you calling for sudo / root privileges. are you in root login in your term when you run this?

most linux systems have to have administrator rights to reboot, halt, shutdown, the system so not every hey day kiddo with an account can just shut it down. Because Linux is a mulituser system. It is designed to be used by more then one person at a time. therefore only a "responsible person" is to be given these rights to shutdown, or reboot, the system. that is where sudo comes in.

but because of its wide use of people that do not actually use Linux as a Multi User system. they give themselves sudo, instead of using root user. or su or su -

others that think they know what is best for others that use their distros have taken away these users freewill to an extent by "hiding" root. Instead of allowing a root account, and letting their users learn what they know. How to use a root user account. they instead take that away from them.

that being said.

what do you think the answer to your question should be?
 
Old 12-03-2016, 07:12 PM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 10,045

Rep: Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158Reputation: 2158
Quote:
Originally Posted by yoda2016 View Post
no sudo in use that im aware of, could it be when i set my machine up i gave a root password, then set up my user profile as administrator, just trying to iron out any problems for future reference
to add to what I already posted on this to you, so you can take from it what you will. As I posted in my dosto forum on shutdown a question on what to write be cause I do not use it, therefore I was not knowing how, then figured it out, after I posted my question on how to properly do so.

Quote:
You're not going to be able to test your friend's script unless he's on Void, or perhaps another runit-based distro. Void's shutdown is not the standard Linux command. The man page makes clear what options are not supported.

And the reason is ...drum roll...
It's a script.that uses runit to perform the shutdown. Probably to make sure runit does it's own process killing before halting.

Once executed, it sleeps without forking (because it's a shell script), so if you run it in a terminal or VT, that terminal is occupied unless you ctrl-c out (which will cancel the shutdown script).

The proper syntax is
shutdown -h now
shutdown -h +3 for shutdown 3 min from now.
-h +mins 1 - the error you saw said your time spec was illegal and it chose to shutdown "now".

It's similar to what I'm familiar with in OpenBSD (+mins as a timespec, but they also support absolute times, and they print the PID and fork the process (it's binary) so to cancel it, you just kill the PID).

To test the more common version of shutdown, you'll need to boot one of your other installs.
so now you know what your script is doing to that terminal. shutdown , the proper way it is to be used is within the terminal itself and not a bash script. so I do wonder what is your motivations for doing this is. I just was letting you and not questing you, figuring you're just wanting to learn something.

so now hopefully with that extra bit of information on what calling shutdown in a terminal actually does you have learned more then you bargained for.

but for whatever your reasons to run a script to shutdown the system. they are just that.

so if you are wanting to use this for just your system, then write it accordingly, but for other systems too. you need to question, Will that even use it? is this something they can do themselves? etc...

Last edited by BW-userx; 12-03-2016 at 07:52 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 09:03 AM
My first try with scripting alaios Programming 14 03-15-2013 04:35 AM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration