You are not logged in.

#1 2017-03-28 16:15:33

peterklarc
Member
Registered: 2017-03-28
Posts: 28

run command only once

Hello,

I have a script with the command:

pacman -Sl 

I want that when the user runs the gui dialog that command only runs once that day or only that time until the next 5 or 6 times the user uses the gui.
Thanks.

Offline

#2 2017-03-28 16:41:47

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: run command only once

So, even if the user immediately reruns the GUI, the command itself is not executed? That seems like an odd thing to do. What are you trying to acheive? This sounds like a classic X-Y problem.


Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2017-03-28 16:51:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: run command only once

You could cache the results in a file and check the age of the file.  But in this case that really makes no sense.  `pacman -Sl` gets a list of packages in the local sync database: this is already stored locally.  There is nothing saved by caching the results yourself.

But if you must cache the results yourself, then there is also no need to invalidate that cache after 5-6 runs of the gui nor the next day: that cached output will remain valid until the next update of pacman's database (e.g. pacman -Sy(u)).  You could easily check this by comparing the age of your cached file age of the database files /var/lib/pacman/sync/{core,extra,community}.db.  In bash:

mycache=/path/to/your/file
sync=/var/lib/pacman/sync/
[[ $mycache -ot ${sync}core.db || $mycache -ot ${sync}extra.db || $mycache -ot ${sync}community.db ]] && pacman -Sl > $mycache

I agree with the XY issue here.  Are you trying to build a GUI wrapper for pacman?  What step are you trying to implement with this?  Why not use libalpm?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2017-03-28 22:59:22

peterklarc
Member
Registered: 2017-03-28
Posts: 28

Re: run command only once

Hi,
Thanks all for your time.

Trilby wrote:

...this is already stored locally

My mistake...a lot of tabs and files open at same time roll
-----
Just building my post install with stuff that I always use and end up with this idea.

Thanks.

Offline

Board footer

Powered by FluxBB