Is this the "right" way to make an alarmclock?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Is this the "right" way to make an alarmclock?
# 8  
Old 09-22-2011
This is probably another thread, but what's the best way to do config
files. At the moment, I just use...

cat config_file|grep var_name|cut -d'=' -f2

... which is fine for what I've been doing, but I'm not sure what to
do when there are a variable number of entries and I want it go through
them like a list.

Course, the config file itself could be a script but I prefer to keep
the configs seperate from the functions. Not really sure how to do
this. It's a problem sometimes, though I can usually hack up some kind
of work-around for my ignorance.
# 9  
Old 09-22-2011
Quote:
Originally Posted by ninjaaron
...
Is there any reason my rather humble implementation is undesirable or
problematic?
If you plan to deploy that alarm into a mission critical process daylight saving time and in general adjustments to the system clock may be problematic for your script.
This User Gave Thanks to cero For This Post:
# 10  
Old 09-22-2011
Quote:
Originally Posted by ninjaaron
This is probably another thread, but what's the best way to do config
files.[...]
Yep, please start a new thread for new questions.
# 11  
Old 09-22-2011
Quote:
Originally Posted by cero
If you plan to deploy that alarm into a mission critical process daylight saving time and in general adjustments to the system clock may be problematic for your script.
Great to know! Thanks.

---------- Post updated at 05:26 PM ---------- Previous update was at 04:58 PM ----------

Quote:
Originally Posted by pludi
Yep, please start a new thread for new questions.
done, sir.Smilie
# 12  
Old 09-22-2011
Quote:
Originally Posted by ninjaaron
Code:
#!/bin/bash

time="$1"
command="$2"
trig=0

while [ $trig = 0 ]; do
	if [ "$(date +%R)" = $time ]; then
		$command
		trig=1
	else
		sleep 5
		
	fi
done
exit

In my opinion, your simple script is too complex. Smilie

Why not directly use the date-$time check as the loop condition? This way, $trig is not needed. Also, it may be more useful to have this script return the exit status of $command.

For your consideration:
Code:
#!/bin/sh

time="$1"
command="$2"

while [ "$(date +%H:%M)" != "$time" ]; do
	sleep 5
done
$command

Also, for portability, I made some minor modifications that may not be of any interest to you.

Since there's nothing bash-specific about this little script, I changed /bin/bash to /bin/sh. Should you ever need to run it on a system that does not have bash, it will still work.

A system without bash may have a date command that does not support the %R format. Since that's equivalent to the standard %H:%M, I used that instead.

Regards,
Alister

Last edited by alister; 09-22-2011 at 12:17 PM..
This User Gave Thanks to alister For This Post:
# 13  
Old 09-23-2011
That's excellent. I'm always happy to see better ways of doing it. I just somehow had it in my head that it would be an if condition before I started, so it never occured to me to put the condition in the loop itself.

Smilie
# 14  
Old 09-24-2011
Whats ABSG got to do with this thread?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Make scipt except from "Y","y" and "yes" to take [Enter] as being "yes"

This is the script: #!/bin/sh if ; then rm -rf /usr/share/WallpaperChanger; fi if ; then rm -rf /usr/bin/wallch; fi; if ; then rm -rf /usr/share/applications/wallch.desktop; fi if ; then rm -rf /usr/share/doc/wallch; fi if ; then rm -rf /usr/share/man/man1/wallch.1.gz; fi echo "Delete... (4 Replies)
Discussion started by: hakermania
4 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Programming

how could i make a program mixed with many "|", "<" and ">"

I have written following code to do: ls -l | wc -w, it works: but when there are not only a single "|", if there are more such as: ls -l | sort -r | sort | sort -r, This program does not work, i want to know how could i deal with it when there are more "|", another situation is that, if it mixes... (2 Replies)
Discussion started by: strugglingman
2 Replies

9. UNIX for Dummies Questions & Answers

"./cofigure" and "make" turmoil

I am a Unix newbie and I downloaded some X11 programs. I have gcc, but I cannot compile the files. I NEED HELP!!!! :confused: (16 Replies)
Discussion started by: gnerd
16 Replies
Login or Register to Ask a Question