Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Modulus Operator, Simple Shell Script
etangman
post Jun 12 2008, 06:55 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 12-June 08
Member No.: 13,504



Alright, I am attempting to add records to a database, but I need them to be divisible by 30 so that I can update them concurrently.
In order to do this I intended to use `date +%s` to get the current time in seconds, and then add 1 until the number was divisible by 30.
To simplify things I made $now equal to a number I knew was divisible by 30 for testing, but the modulus operator doesn't work.
I'm assuming my syntax is wrong, but everything I've looked at makes it look right to me. The increment operator wouldn't work either...
Any help would be much appreciated because I'm at a standstill with this nonsense. Thanks.

#now=`date +%s`
now=1213204110
tmp=0

if [ $now%30 != 0 ]
then
while [ $now%30 != 0 ]
do
tmp=`expr $now + 1`
now=$tmp
done
fi

echo $now
Go to the top of the page
 
+Quote Post
michaelk
post Jun 13 2008, 05:58 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,800
Joined: 23-January 03
Member No.: 360



Lots of help can be found on bash shell scripts by googling. However, here is one method to accomplish the task.

CODE
now=`date +%s`
#let now=1213204110
divisor=30

let "remainder = $now % $divisor"

until [ "$remainder" == 0 ]
do
   let "now +=1"
   let "remainder = $now % $divisor"
   echo $now
done

echo $now is divisible by 30
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 24th November 2017 - 04:18 AM