how do i begin with a script when testing if it don't exist
how do i begin with a script when testing if it don't exist?
while [ the file don't exist ]; <----- how should this test be?
do
sleep
done
do
sleep
done
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Compared to eternity 6 years is still a short time, but nevertheless it might be a good idea to let the script continue:
or
Code: Select all
while [ ! -e /path/to/file ]
do
sleep 1
done
Code: Select all
until [ -e /path/to/file ]
do
sleep 1
done
Funny guy!drunkjedi wrote:Aha, musher doing a pelo act? Lol.
Not really!
I thought it resembled this script which I wrote in 2015 (?) to keep
updated the slocate databases of file names. Some of those lines I owe to
French member Médor, who in turn borrowed a few from our venerated
Puppy founder, BK.
This script actually sleeps 95 % of the time.
BFN.
~~~~~~~~~~~~~
Code: Select all
1 #!/bin/ash
2 # ash is used because of it is +/- 50 % faster than bash.
3 # Filename: $SLOC/auto-updatedb-slocate.sh, # with link in /root/Startup.
4 # Purpose: update the slocate database at every x interval of time.
5 #
6 # Thanks to French member Médor for having found the "while" time loop
7 # below, and to member Uten for the 'nice' (pun intended! :-) tip.
8 #
9 # (c) Christian L'Écuyer (alias musher0), Gatineau (Qc), Canada, 12 & 19 févr. 2015, 14 oct. 2015.
10 # Rév. 3 févr. et 28 févr. 2016. GPL2
11 ####
12 export SLOC="/root/my-applications/SLocate" # variable
13 sleep 4m # With this line, slocate will start to update its
14 # db's exactly 4 minutes after your Puppy session has started.
15 # After that run is finished, they'll be updated at the interval
16 # you un-commented below (see lines 28 to 37).
17
18 while [ 1 ]; do # This script updates all the slocate db's'
19 # in the background, without imposing on your use of the computer.
20 ionice -c 3 nice -n 19 $SLOC/Slocate-updt-all-no-text.sh &
21 # ionice, etc. is from K. Lindsay's original /etc/cron.daily/slocate
22
23 # We can take the opportunity to add here any number of other
24 # commands that we want executed periodically in the background.
25 sync;echo 3 > /proc/sys/vm/drop_caches
26 wait
27 # The above cleans the RAM caches and frees up RAM. *
28
29 # Uncomment ONLY ONE LINE BELOW corresponding to your use (time interval).
30 # sleep 20m # every 20 minutes # Use these short intervals only
31 # sleep 30m # every 30 minutes # if you absolutely need to. The
32 # sleep 45m # every 45 minutes # slocate DB process imposes a lot
33 # sleep 1h # every hour ######## of wear on your drives.
34 # sleep 90m # every hour and a half
35 # sleep 2h # every 2 hours
36 # sleep 150m # every 2 hours and a half
37 sleep 3h # every 3 hours
38 # sleep 210m # every 3 hours and a half.
39 done
40
41 ####
42 # * Derived from : auto_clean_mem, by Médor, 2015-02-08. Source :
43 # http://murga-linux.com/puppy/viewtopic.php?p=826916&sort=lastpost#826916
44 # Retrieved 09.02.2015 13:43:49. # According to Médor, he modeled
45 # this loop on one used by BK on the Internet connection.
46 #
47 # Also thanks to Uten for his post at:
48 # http://murga-linux.com/puppy/viewtopic.php?p=828580&sort=lastpost#828580
49 # Retrieved 19.02.2015 14:24.
50 ####
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
not to create a new topic to answer a question already poste
I fully agree with Musher0 not to create a new topic to answer a question already posted..
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Completely different. No while loop, no sleep ... for periodical checking tasks you should use a cron job, not a permanently running script.drunkjedi wrote:MochiMoppel, what should the script looks like if I want it to look for change in file or folder?
Not that I claim to understand what enhu asked for. The thread title makes no sense to me. I only assumed that his script halts until a non-existent file finally is created an then continues. At least it doesn't look as if he was asking for a permanent loop.
Code: Select all
#!/bin/ash
# CacheNewFont.sh
#
# For "drunkjedi"
#
# Goal: Recreate the font cache if we intalled
# ----- a new font during the current hour.
# -------------------------- ========= ----
#
# Note -- This script is still "raw". It needs to be refined.
# ------- It is presented only for discussion purposes.
#
# musher0, 28 déc. 2016
####
Hour="`date '+%H:'`" # Assuming 24 h clock on your system.
Day="`date '+%d:'`"
cd /usr/share/fonts/default/TTF
RecreatE () { [ "`ls -Algot *.ttf | awk '$1 ~ /-rw/ && $5 ~ /'$Day'/ && $6 ~ /'$Hour'/'`" ] && fc-cache -r || echo -e "\n\t\tNo need.\n"; }
RecreatE # Presented as a function because we might want to repeat
# it at a certain interval. For ex.:
# while [ 1 ];do
# RecreatE
# sleep 1h
# done
- Attachments
-
- CacheNewFont.jpg
- (10.47 KiB) Downloaded 170 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
I found inotify-tools in Fatdog, I don't know if other puppies have it.Can be used to detect if a file is moved to or is created in a directory....
Exit status returned by inotifywaitI will test this in few min..
Code: Select all
inotifywait -m /usr/share/fonts/default/TTF -e create -e moved_to
Exit status returned by inotifywait
Code: Select all
Exit status:
0 - An event you asked to watch for was received.
1 - An event you did not ask to watch for was received
(usually delete_self or unmount), or some error occurred.
2 - The --timeout option was given and no events occurred
in the specified interval of time.
Ok I don't know why this script doesn't workWhile this does
Maybe I should try piping the ouput of inotifywait -m.
Code: Select all
while inotifywait -m -e create,moved_to /mnt/sda8/test/xyz; do exec /mnt/sda8/test/Script; done
Code: Select all
while inotifywait -e create,moved_to /mnt/sda8/test/xyz; do exec /mnt/sda8/test/Script; done
Code: Select all
-m |--monitor Keep listening for events forever or until --timeout expires.
Without this option, inotifywait will exit after one event is received.
Ok this worksEvery time a file is made in the folder /mnt/sda8/test/xyz, the script /mnt/sda8/test/Script gets run.
Which was just a xmessage.
Is this the right way?
Code: Select all
inotifywait -m /mnt/sda8/test/xyz -e create -e moved_to |
while read a;
do /mnt/sda8/test/Script
done
Which was just a xmessage.
Is this the right way?