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 04-27-2017, 02:27 AM   #1
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 197

Rep: Reputation: 5
Turning on/off output


I have unit named ARCO connected over USB to Tomato based ASUS router.
It is equipped in /bin/sh not in bash. The unit is equipped in 4 relay outputs. The command
Code:
./arco
returns current output states in the form of one hex digit command. If I want to set for example output no 2 I have to use command:
Code:
./arco 2
But the number after ./arco command must be in decimal form.
I want to turn off/on particular output in pre-defined time.

The part of program responsible for that looks like this:

Code:
if [ "$czas" -gt "$out4_off" -o "$czas" -lt "$out4_on" ]                     
then                                                                         
set=$((0x$out & ~2))                                                         
else                                                                         
set=$((0x$out |2))                                                          
fi                                                                           
if [ "$czas" -gt "$out4_off_1" -o "$czas" -lt "$out4_on_1" ]                
then                                                                        
set=$((0x$out & ~2))                                                        
else                                                                        
set=$((0x$out | 2))                                                         
fi
The variables represents as follows:
Code:
czas - actual time in my time-zone
out4_off - time of turning off particular output for the first time
out4_on - time of turning on particular output for the first time
out4_off_1 - time of turning off particular output for the second time
out4_on_1 - time of turning on particular output for the second time
set - represents number which will be written to ARCO unit over USB
All time values are represented in minutes from midnight.

Value of out4_on_1 is grater than out4_on
and similar
Value of out4_off_1 is grater than out4_off

In case of my program, the first "if" will for example set output to ON, but the second "if" statement set it again to OFF.
How can I modify the program above, to be sure that the result of first "if" statement will not be overwritten by second "if" and vice-versa.
Any idea?

Last edited by mackowiakp; 04-27-2017 at 02:33 AM. Reason: Adding info
 
Old 04-27-2017, 05:05 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,146

Rep: Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935
Depending on what that shell actually is, you may have else-if support; something like this
Code:
if [ "$czas" -gt "$out4_off" -o "$czas" -lt "$out4_on" ]                     
then                                                                         
  set=$((0x$out & ~2))                                                         
else if [ "$czas" -gt "$out4_off_1" -o "$czas" -lt "$out4_on_1" ]                
then                                                                        
  set=$((0x$out & ~2))                                                        
else                                                                        
  set=$((0x$out | 2))                                                         
fi
untested of course ...
 
1 members found this post helpful.
  


Reply

Tags
shell script


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
Giving wrong output with sh but correct output with command entry in Ubuntu bison72 Linux - Newbie 3 10-14-2015 11:27 PM
Requests to my ISP server are output in the middle of output by any command I run. stf92 Slackware 2 07-10-2012 08:38 AM
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
Standard script output to screen & -x option output to file BoBeau236 Programming 6 05-10-2011 07:43 AM
ps -eH | grep java output in a active passive clustered output johnkalikavunkal Linux - Server 2 01-30-2009 11:21 PM

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

All times are GMT -5. The time now is 10:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration