LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-18-2014, 05:08 PM   #1
iExe
LQ Newbie
 
Registered: Dec 2014
Posts: 1

Rep: Reputation: Disabled
Smile I need help for Bash scripts/commands [shutdown/halt]


1. Write a command that will:
a) shutdown the system in 25 minutes
b) halt the system immediately

2. Write a script called "shutdown" that accepts the initial OS shutdown value (seconds) as a command-line argument and after that shuts down the operating system. The scrip should prints output similar to the following:
>>user$ ./shutdown.sh 4
4
3
2
1
System will shut down immediately!

Thanks for your help!
 
Old 12-18-2014, 05:13 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Show us what you've done and where you're having problems and we'll offer assistance, but we don't answer homework questions verbatim.
 
Old 12-18-2014, 08:30 PM   #3
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
cool see
Code:
man shutdown
for your hint to this question.

and show us some effort.
 
Old 12-18-2014, 11:07 PM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
1) For first 25min one:

-----------------------
#!/bin/bash

echo Shutting down in 25 minutes...
sleep 25m
shtudown -h now
----------------------

2) For immediately:

--------------------------
#!/bin/bash
echo Shutting down the system immediately...
shutdown -h now
--------------------------

3) For shutdown in seconds with countdown

------------------------------
#!/bin/bash

ARG1="$1"

echo Shutting down in $ARG1 seconds...
while [ $ARG1 -ne 0 ]; do
echo $ARG1
ARG1=$(($ARG1-1))
sleep 1s
done

echo "System will shut down immediately!"
shutdown -h now
-----------------------------

Just type in the text between the hypenated lines in a text files. And run

chmod u=rwx filename
and run

./filename
or in case of last script
./filename 4

and there you go.

Enjoy!!!
 
1 members found this post helpful.
Old 12-19-2014, 12:50 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It sounds like a homework assignment...
 
Old 12-19-2014, 01:56 AM   #6
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
@OP well you found the cooked solution for this one:

for 1: try looking on "at" that 's quite clean and good for these sorts of tasks.. i would not prefer telling the shell to sleep for 25 mins
i am suggesting so you can do your assignments on your own next time..
 
Old 12-19-2014, 05:41 PM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Homework. ... A.....
 
  


Reply



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
How to restrict Shutdown/Reboot/Halt/init commands for root Haris1387 Red Hat 4 09-03-2013 09:01 AM
Where are BASH commands stored? Not scripts but what bash exe uses. theKbStockpiler Programming 11 02-23-2011 03:06 PM
whats the diffrence between shutdown and halt commands??? Fond_of_Opensource Linux - Newbie 1 12-20-2006 05:35 AM
Bash scripts do not echo commands sean@responsivedata. Linux - Newbie 9 01-17-2006 10:25 AM
Bash scripts do not echo commands sean@responsivedata. Linux - Software 3 01-13-2006 09:03 PM

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

All times are GMT -5. The time now is 07:56 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