Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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?
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.
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
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.
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
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
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.
#!/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
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
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?
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.