LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2012, 10:57 AM   #1
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Rep: Reputation: 0
bash: countdown


So I see some post on this when doing a simple google search but none seem to fit what i want and almost feel my idea is almost just as good and I like getting your opinion. So before I start getting into details about what I need I think I should tell you a little about my script. I'm writing a script that will send a countdown to a screen and right now I pretty much have that all done already but the problem this is a set time. I also just added an argument check for the text now to just shut down right then and there no countdown. So i think now we are ready for what I need.

What I need is (I believe) a countdown of some sort so I can make it so you can enter any time and when the countdown timer reaches that many seconds it displays a message to my screen how many seconds are left before the server goes down.

also while we are here lets also find out how to keep sleep commands from interupting my terminal if we can please? thank you
 
Old 11-04-2012, 12:39 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Can we see what you've got already? You should just need to use the 'sleep' command.

Quote:
also while we are here lets also find out how to keep sleep commands from interupting my terminal if we can please? thank you
You mean tasks which you've sent to the background? You can redirect their I/O:

Code:
command >/dev/null 2>&1 &
should work, I believe.
 
Old 11-04-2012, 01:01 PM   #3
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
This process is running foreground if possible to do it like that and just make sleep commands not interupt me but still do everything else as normal I just want to be able to continue my work while I'm waiting for the server to shutdown if I put sleep in the background it seems to do everything instantly? (thats when I put only sleep in the background of code).

sleep command will not work for my situation if I've figured this out correctly cause it could be any given time I put in and I need on elike 60 seconds or 30 seconds there to be a message how would i tell it to sleep for sure everytime will theres a minute left?get what I mean? and well i guess I can show you what I've got at least but it really doesn't tell you much. but here goes nothing! gonna shorten the example up of unneccsary stuff because I am using ssh almost all the time because I'm on my laptop always either away from home and just home and the chair the computer desk has is broken (very uncomfortable) also if there are any mistakes in the code below i promise you they are not actually in the code itself since I can't figure out how to copy and paste the ssh terminal vim i can't just do a simple copy paste to my windows -.-

Code:
#!/bin/bash

screen -S PhantasyCraft -X stuff "say Server will restart in 30 seconds!^M"
sleep 15
. . .
#more of the same thing over and over again just different stuff and different sleep times
screen -S PhantasyCraft -X stuff "say Server will restart in 1 second!^M"
sleep 1
screen -S PhantasyCraft -X stuff "say Server will restart NOW!^M"
screen -S PhantasyCraft -X stuff "stop^M"
sleep 10
startphantasycraft
#the above startphantasycraft is a a symlink to a script i wrote that you don't need anything from it has no real effect on our results
Maybe it will help more then i think but like I say I wanna be able to type in like restartphantasycraft 89 and have it say restarting in 89 seconds and then the next mesage always be at 1 minute maybe and then next 30 seconds so I mean i need a count down of some sort to tell it when I hate 60 cause if that variable keeps changing i can't have a set sleep time and like if it keeps up to 300 seconds i want it to say like 300seconds til restart it needs to work interchangably
 
Old 11-05-2012, 03:59 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by fatalerror0x00 View Post
This process is running foreground if possible to do it like that and just make sleep commands not interupt me but still do everything else as normal I just want to be able to continue my work while I'm waiting for the server to shutdown if I put sleep in the background it seems to do everything instantly? (thats when I put only sleep in the background of code).
Here:
Code:
echo "Shut down in 5 seconds!"
(sleep 5; echo "Shutting down!") &
will print "Shut down in 5 seconds", then return you to your prompt (so you can run whatever commands you like) and after the 5 seconds are up will print "Shutting down". Is that what you wanted?

Quote:
sleep command will not work for my situation if I've figured this out correctly cause it could be any given time I put in and I need on elike 60 seconds or 30 seconds there to be a message how would i tell it to sleep for sure everytime will theres a minute left?get what I mean?
I'm not sure I do get what you mean... Something like:

Code:
seconds=10
(
for i in $(seq $seconds -1 1); do
    echo "$i seconds to shutdown...";
    sleep 1;
done;
echo "Shutdown now!") &
 
Old 11-05-2012, 10:45 AM   #5
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
yes thats what i wanted and when I said sleep command wasn't what i wanted that was wrong. I some reason put that there NOT thinking :P. But we will try this for statement cause thats pretty much waht I though would work. but I didn't know how to put it together and is a different style of an for statement then expected but it all works for me.

only issue still at this moment til I test this for statememt is that i cannot get sleep to run so that it doesn't interupt my terminal nothing I find works as soon as in anyway theres a & after it on the same line sleep just says no not gonna run :P and this is driving me insane. I've always hated the sleep command for this one reason nothing seems towork
 
Old 11-05-2012, 10:49 AM   #6
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
So actually the everything in ( ) worked actually not when it echoes something it's a little annoyingbut thats fine I'm thinking of getting rid of anyway so we should be good till i figure out that for statement and get it implemented
 
Old 11-05-2012, 04:46 PM   #7
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
So i implemented my own stuff to this for statement (my if statements to check what i enntered and/or to see if the current amount of seconds left equals any of the if's till it reaches zero and stops the server. Right now it just keeps saying the same result over and over again so after the countdown reaches 0 it still doesn't the same thing

example i type in stopphantasycraft 15 means 15 seconds (it's my minimum for the argument other then the string now) so the text server will stop in 15 seconds comes up 15 times and then the server doesn't shutdown it just stops but theres an if when the countdown reaches 0 to issue the stop command but it's not even counting down some reason I had this issue i thought i fixed it and so i added all my if statements and it's back

FIXED: I was using the wrong variable we are all good now this works now. SOLVED!

Last edited by fatalerror0x00; 11-05-2012 at 05:08 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
Countdown timer for Linux? kona0197 Linux - Newbie 19 06-30-2019 01:41 PM
countdown clock timl Linux - General 2 04-11-2011 01:52 PM
Countdown while booting the CD could be helpful pxumsgdxpcvjm Slackware 4 06-19-2006 07:47 PM
Countdown clock - how hard could it be? krock923 Linux - Software 1 07-21-2004 11:07 PM
Countdown to the new LOTP isajera General 26 03-03-2003 09:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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