Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 20 Oct 2017, 17:32
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
how do i begin with a script when testing if it don't exist
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Wed 22 Sep 2010, 03:42    Post subject:  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
Back to top
View user's profile Send private message Visit poster's website 
musher0


Joined: 04 Jan 2009
Posts: 10965
Location: Gatineau (Qc), Canada

PostPosted: Mon 26 Dec 2016, 23:05    Post subject:  

Hello enhu.

It seems that your non-existent program will simply sleep forever? Wink

BFN.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1367
Location: Japan

PostPosted: Mon 26 Dec 2016, 23:35    Post subject:  

Compared to eternity 6 years is still a short time, but nevertheless it might be a good idea to let the script continue:

Code:
while [ ! -e /path/to/file ]
do
sleep 1
done

or
Code:
until [ -e /path/to/file ]
do
sleep 1
done
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Tue 27 Dec 2016, 03:06    Post subject:  

Aha, musher doing a pelo act? Lol.
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10965
Location: Gatineau (Qc), Canada

PostPosted: Tue 27 Dec 2016, 05:15    Post subject:  

drunkjedi wrote:
Aha, musher doing a pelo act? Lol.
Funny guy! Laughing

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:
     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
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
Pelo

Joined: 10 Sep 2011
Posts: 12591
Location: Mer méditerrannée (1 kms°)

PostPosted: Tue 27 Dec 2016, 20:07    Post subject: 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..
_________________
Passenger Pelo ! don't ask him to repair the aircraft. Don't use him as a demining dog .... pleeease.
Back to top
View user's profile Send private message Yahoo Messenger 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Wed 28 Dec 2016, 00:58    Post subject:  

Don't take seriously Pelo, I was just jesting.

MochiMoppel, what should the script looks like if I want it to look for change in file or folder?

Let's say, I added few fonts, want to run update_fonts automatically.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1367
Location: Japan

PostPosted: Wed 28 Dec 2016, 02:07    Post subject:  

drunkjedi wrote:
MochiMoppel, what should the script looks like if I want it to look for change in file or folder?
Completely different. No while loop, no sleep ... for periodical checking tasks you should use a cron job, not a permanently running script.

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.
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10965
Location: Gatineau (Qc), Canada

PostPosted: Wed 28 Dec 2016, 03:46    Post subject:  

Code:
#!/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
CacheNewFont.jpg
 Description   
 Filesize   10.47 KB
 Viewed   154 Time(s)

CacheNewFont.jpg


_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Wed 28 Dec 2016, 05:50    Post subject:  

I found inotify-tools in Fatdog, I don't know if other puppies have it.
Code:
inotifywait -m /usr/share/fonts/default/TTF -e create -e moved_to
Can be used to detect if a file is moved to or is created in a directory....

Exit status returned by inotifywait
Code:
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.
I will test this in few min..
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Wed 28 Dec 2016, 09:34    Post subject:  

Ok I don't know why this script doesn't work
Code:
while inotifywait -m -e create,moved_to /mnt/sda8/test/xyz; do exec /mnt/sda8/test/Script; done
While this does
Code:
while inotifywait -e create,moved_to /mnt/sda8/test/xyz; do exec /mnt/sda8/test/Script; done
Code:
   -m |--monitor     Keep listening for events forever or until --timeout expires.
                    Without this option, inotifywait will exit after one event is received.


Maybe I should try piping the ouput of inotifywait -m.
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Wed 28 Dec 2016, 10:15    Post subject:  

Ok this works
Code:
inotifywait -m /mnt/sda8/test/xyz -e create -e moved_to |
   while read a;
      do /mnt/sda8/test/Script
done
Every 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?
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 684

PostPosted: Wed 28 Dec 2016, 10:20    Post subject:  

Or should I echo it's exit status and run the script if it's 0?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0684s ][ Queries: 12 (0.0118s) ][ GZIP on ]