maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   slocate (https://talk.maemo.org/showthread.php?t=16332)

albright 2008-02-08 12:03

slocate
 
anyone know where to get a version of slocate that
will run on the n810 (os2008)? TIA,

free 2008-02-08 12:48

Re: slocate
 
I thought about porting it (slocate is very usefull yes) but slocate database needs to be frequently updated, through cron. There is no cron tasks by default (but cron system is there). I wonder if there is a reason (performance or anything related).. ?

Benson 2008-02-08 14:14

Re: slocate
 
Quote:

Originally Posted by free (Post 139776)
I thought about porting it (slocate is very usefull yes) but slocate database needs to be frequently updated, through cron. There is no cron tasks by default (but cron system is there). I wonder if there is a reason (performance or anything related).. ?

Well, battery life will suffer... it's just like metalayer-crawler. But it should work, even without cron. Either start at every boot, or let the user manually run it when they want. slocate can run without cron.

Oh wait, I'm thinking like a slackware :eek:, or worse, a UNIX :eek::eek: man.
This is debian, so slocate package must depend on cron, because you typically want to run it that way, and you can't have a package that requires the sysadmin to, you know, admin the sys... ;)

I'd gladly take such a thing, if you could get it with no cron dep. It'd be useful to me if I updated the db once a month, because I'm usually hunting some system file, which don't change much.
Though it occurs to me, the tablets need something like anacron, only power-supply aware. If the tablet's charging (and the battery's over, say, 30% full), and it's been over <24hrs | 1 week | 1 month> since the task was last run, then re-run it... Be a good project for me, when I get time :)

albright 2008-02-08 14:54

Re: slocate
 
why not just run a script something like this:

while true
do
sleep 24 hrs
if charging
then
updatedb
done

I usually leave my n810 plugged in over night,
so if I start this script at the right time ....

is there a problem with faking cron like this?

anyway, I'd be happy to run slocate manually so
I hope it gets ported (there is a version for the
770 it seems but it won't install on the n810
see: http://lucidvisions.com/#nes)

rcull 2008-02-08 15:44

Re: slocate
 
There is a simpler way.

create two scripts in /usr/bin called updatedb and locate

updatedb
Code:

find / -print > /medi/mmc2/locate.db
locate
Code:

grep "$1" /media/mmc2/locatedb | more
then use
Code:

crontab -e
to add the following line in roots crontab

Code:

0 4 * * * /usr/bin/updatedb
then to run just use
Code:

locate leafpad
Rick

Benson 2008-02-08 17:13

Re: slocate
 
Albright, that'd work for a while, but eventually the execution time of the rebuild makes drift out of sync, and then you could go weeks without an update.

A better thing is to check once an hour or so, so (assuming your plug-in at night is precisely periodic), it'd drift an hour, then get caught on the "previous" iteration. But then you do have to check when it was last run so you aren't running it 6 times a night. I assume that's what you were trying to dodge.

Try:
Code:

#!/bin/sh
while :; do
  if [ `date +%H` == 00 ] && sleep 10 && [ "x`battery-status|grep Charging`" != x ]; then
    play-sound /usr/share/sounds/ui-wake_up_tune.wav
  fi
  sleep 3590
done

The naive approach (sleep 3600) would skip once in a great while, because even when nothing happens, the condition evaluation and loop overhead cause drift. Every once in a while, it'll be 23:59:59.99 one iteration, and 01:00:00.01 the next, so you'll miss one. We avoid that by fudging the time below an hour, but delaying extra when we do hit so we don't hit it twice in the same hour. You could shift the sleep 10 into the then clause, but then it would sometimes check at 00:00:01, see the battery's not charging, and then check again at 00:59:51 and (if it was plugged in then) then run it. Your choice which behavior is better.



Rick, your
Quote:

Originally Posted by rcull (Post 139833)
locate
Code:

grep "$1" /media/mmc2/locatedb | more

would work, but if you intend to call your script locate, it'd be good to behave a little more like locate. Leave out the '| more', so it could be used in scripts/pipelines.

rcull 2008-02-08 19:34

Re: slocate
 
Benson
It works and has been working for over a year. I use this regularly and find the '|more' extremely usefull. You can of course 'locate libcurl |more' its just more typing.
Rick

Benson 2008-02-08 19:53

Re: slocate
 
Quote:

Originally Posted by rcull (Post 139925)
Benson
It works and has been working for over a year. I use this regularly and find the '|more' extremely usefull. You can of course 'locate libcurl |more' its just more typing.
Rick

Sure it works, but you're replacing a standard command with a broken version. Replacing commands with stripped-down versions, supporting only a subset of functionality, but operating properly within that subset, is quite acceptable. Replacing commands with broken versions to save typing is quite ******ed. Have you ever heard of the alias built-in? Use that to save typing, and don't cram extra functionality into programs to break them!

(In case you're as familiar with tools as with UNIX, you should know that large screwdrivers (14" and up, often smaller ones too) generally have a hexagonal section below the handle, so a wrench may be used when more torque is required to bust a stubborn screw loose.)
It's like saying "Sometimes I need to use a wrench on my screwdriver, so I'll make a screwdriver with a big @#$%ing handle sticking out the side so I can use it that way!"

albright 2008-02-09 00:48

Re: slocate
 
rcull's suggestion is not too bad, but I need more
help with the "crontab -e" command on my
n810 :D

linuxrebel 2008-02-09 07:19

Re: slocate
 
Not to belittle the merits of meaty tools ;) I for one would love slocate. As for cron, why not set it to oncce a week.

rcull 2008-02-09 09:33

Re: slocate
 
Benson

1. If this was one of the UNIX servers I have managed for the last 15 years, yes you would be right but this is a personal tablet. I don't know about you, but I, haven't got the memory of a goldfish and tend to know what I've done from one day to the next so I'm pretty unlikely to use it in another script.

2. Both the script name and the '|more' are obviously optional.

3. I wonder which is the most '******ed' replacing an accurate (and available) time based tool (cron) with a script using 'sleep' or using accurate (and available) tools find and grep in a way they were meant to be used to replace something currently unavailable!

Lastly, I pride myself on having manners something you are obviously Not Familiar with.

Albright

A useful header for crontab files

Code:

#############################################################################
#                        crontab fields
#
#                          * * * * * [command]
#                          | | | | |
#  minutes 0-59,10,15 ------- | | | ------ day of the week 0-7,3,5
#                            | | |
#      hours 0-23,3,5 -------- | ------- month 1-12,5,7
#                              |
#                    Day of the month 1-31,19
#
#  A "-" (dash) denotes a range and a "," (comma) distinct values
#
#  for example 1-3 in the hours would specify run at hours 1,2 and 3         
#  whereas 1,3 in the hours would specify run at just hours 1 and 3
#############################################################################

Some modern cron implementations allow you to use month and day names as well I haven't tested this on the tablet.

Regards
Rick

qwerty12 2008-02-09 10:39

Re: slocate
 
Thanks for the script rcull, I used it fine. I have a cron service running, and I chmodded the scripts and edited crontab with leafpad.

Although 2 unintended mistakes in scripts.

Meia should be media and locatedb should be locate.db (or the other way around depending on which script you edit first

albright 2008-02-09 16:51

Re: slocate
 
I must be pretty dense, but I can't find any
crontab command on my n810 and there
doesn't seem to be any cron service available.

(I *know* what cron is and the syntax - I
just don't know how to install the cron
service on my n810).

qwerty12 2008-02-09 17:00

Re: slocate
 
Search for cron on this forum, I found a attachment that installed cron (it doesn't come with the ITT by default).

BTW: Is there any vi for dummies? The only command I know is :wq :\

I had to use some own tricks & leafpad to edit cronttab.

albright 2008-02-09 22:54

Re: slocate
 
thanks Faheem - found it

very basic vi:

i - insert mode
esc - exit insert mode
ZZ - save & exit vi

editing more less works as expected

qwerty12 2008-02-10 07:26

Re: slocate
 
Thanks for that :) vi was killing me lol.

rcull 2008-02-10 08:17

Re: slocate
 
qwerty12

A very good vi reference card (pdf)
http://limestone.truman.edu/~dbindner/mirror/vi-ref.pdf

A nice tutorial
http://http://www.eng.hawaii.edu/Tutor/vi.html

regards
Rick

Benson 2008-02-11 16:30

Re: slocate
 
Quote:

Originally Posted by rcull (Post 140163)
Benson

1. If this was one of the UNIX servers I have managed for the last 15 years, yes you would be right but this is a personal tablet. I don't know about you, but I, haven't got the memory of a goldfish and tend to know what I've done from one day to the next so I'm pretty unlikely to use it in another script.

My point was not that you would use it in a script (and watch it fail), but that you would be unable to use it in a script -- or, more importantly, a pipeline. And when you post in a public forum, it's not just your personal tablet. You're advising other people to install a script with wrong behavior on their systems without even mentioning the utility/convenience tradeoff you chose to make.
Quote:

2. Both the script name and the '|more' are obviously optional.
Obviously to you and me, but not necessarily obvious to everyone who reads the forum. I was a beginner once, and would type things in without trying to understand them. Then I'd tinker with them to try to get it. While this script is small enough most people should understand, realize what the | more did, and remove it, there are some who wouldn't. All I tried to do with my first comment was point out that it was optional, and that there were reasons to consider removing it, instead of presuming everyone else would catch it.
Quote:

3. I wonder which is the most '******ed' replacing an accurate (and available) time based tool (cron) with a script using 'sleep' or using accurate (and available) tools find and grep in a way they were meant to be used to replace something currently unavailable!
Wow, 2 strawmen in one sentence.
  1. I didn't suggest calling this crond! You could write a real crond in shell script, using the techniques applied in this, but I would strongly advise against calling anything that runs only one fixed task on a fixed schedule by the name of a general purpose tool. (That would be ******ed!) That script was intended as a separate daemon to solve one problem, while cron was (to my knowledge) unavailable.
  2. My claim was not that using find and grep to replace locate was ******ed, but that taking that (admirable, in itself) locate replacement and breaking it by sticking extra functionality in is ******ed, and I'll stand by that.
Quote:

Lastly, I pride myself on having manners something you are obviously Not Familiar with.
I can see why you'd feel the need to point that out; few would guess it from your suggestions that others might have "the memory of a goldfish". I'd rather be right than polite, but to each his own.

free 2008-02-12 11:10

Re: slocate
 
We now have
not grep ;p
not locate
not slocate
but the great secure and fast Mlocate :D

Quote:

mlocate is a new implementation of locate, a tool to find files files anywhere in the filesystem based on their name, using a fixed pattern or a regular expression. Unlike other tools like find(1), locate uses a previously created database to perform the search, allowing queries to execute much faster. This database is updated periodically from cron.

Several implementations of locate exist: the original implementation from GNU's findutils, slocate, and mlocate. The advantages of mlocate are:

* it indexes all the filesystem, but results of a search will only
include files that the user running locate has access to. It does
this by updating the database as root, but making it unreadable for
normal users, who can only access it via the locate binary. slocate
does this as well, but not the original locate.

* instead of re-reading all the contents of all directories each time
the database is updated, mlocate keeps timestamp information in its
database and can know if the contents of a directory changed without
reading them again. This makes updates much faster and less demanding
on the hard drive. This feature is only found in mlocate.

Either you update the database :
* Through cron (a daily task is installed) or
* Manually by running updatedb (as root)

mlocate will remap your "/usr/bin/locate" and "/usr/bin/updatedb" to point to mlocate binaries.
It creates a new user/group for security reasons.
You can do normal searches:
PHP Code:

locate .mp3 

Or regexp based searches:
PHP Code:

locate -"libosso[^-].*postrm" 

I find it very efficient. I suggest to try it out, I've also put this on my PC and now replaces slocate.

guysoft 2009-06-23 16:00

Re: slocate
 
Wonderful tool. Really had it missing.
It was hard to find because findutils points to busybox.

qole 2009-06-23 17:49

Re: slocate
 
I've put a packaged-up version of cron in my repository (see here), by the way. It's just the one from the forums put into a .deb file.


All times are GMT. The time now is 03:47.

vBulletin® Version 3.8.8