Where do i put my scripts ? best directories? Child script execution

As we know flash memory limited to read so it is about few month max if it reads every 5 secunds

I have a script which has endless loop in it and every 5 secunds child script executed and exit 0

/bin/myservice.sh

###################setup part####################################
echo "setting parametrs"
var1=7
var2=8
######################loop part##########################
while :
	do
                sleep 5
           
              /bin/ash  /bin/mykika.sh $var1   $var2
	done
####################################################

and /bin/mykika.sh

var1=$1
var2=$2
echo "$var1 and $var2"
exit 0

I am afraid that /bin/mykika.sh will be readed from flash every 5 seconds cause it has exit 0

Where is the best directories i put my scripts so they will be read only once and flash wont be used anymore ?
Or how to exucute a script in RAM and be sure about it ?

There is no practical limit in reading.

There is in writing though, but in your case it looks only reading.

I am a long time user and have these kind of scripts running for years e.g watchdog scripts for OpenVPN etc.

Besides bash usually read scripts in blocks of 8 KB and cache in memory (not sure if this is also the case for OpenWRT) so nothing to worry about

2 Likes

i am sure about scripts in loop i cheked it but! waht about child running scripts with exit 0 wich means this copy will be destroyed and the end and then again child script will be runing wich will be read from flash .

Hi

why don't you simply copy your scripts in /tmp before first run ?
it is RAMFS
you could then read/write as you like

2 Likes

I know about /tmp/ and about to do so, but maybe I don't have to, also would like to know maybe there is special directories which runs from RAM in OpenWrt

ll /
drwxr-xr-x    1 root     root             0 Aug 27 23:58 ./
drwxr-xr-x    1 root     root             0 Aug 27 23:58 ../
drwxr-xr-x    2 root     root          1044 Aug 19 16:01 bin/
drwxr-xr-x    3 root     root           940 Aug 27 23:58 dev/
drwxr-xr-x    1 root     root             0 Aug 28 11:11 etc/
drwxr-xr-x   11 root     root           462 Aug 19 16:01 lib/
drwxr-xr-x    2 root     root             3 Aug 19 16:01 mnt/
drwxr-xr-x    5 root     root             0 Aug 27 23:58 overlay/
dr-xr-xr-x  107 root     root             0 Jan  1  1970 proc/
drwxrwxr-x   16 root     root           211 Aug 19 16:01 rom/
drwxr-xr-x    2 root     root            31 Aug 19 16:01 root/
drwxr-xr-x    2 root     root           770 Aug 19 16:01 sbin/
dr-xr-xr-x   11 root     root             0 Jan  1  1970 sys/
drwxrwxrwt   15 root     root           480 Aug 27 23:59 tmp/
drwxr-xr-x    1 root     root             0 Aug 19 16:01 usr/
lrwxrwxrwx    1 root     root             3 Aug 19 16:01 var -> tmp/
drwxr-xr-x    2 root     root             3 Aug 19 16:01 www/


mount
/dev/root on /rom type squashfs (ro,relatime,errors=continue)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/mtdblock6 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
tmpfs on /dev type tmpfs (rw,nosuid,noexec,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,mode=600,ptmxmode=000)
bpffs on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,noatime,mode=700)

as you see /tmp is on tmpfs
and /var is symlinked to it
nothing else

1 Like

so first when service starts i have to copy execs sxript to /tmp/
and then run main script wich will run thase execs from temp

yeah, exactly
copy & run

i use this way for years
all my dynamic scripts,configs and data for SNMP/LLDP/q-bridge-mib/fdb, etc... are placed in /tmp and i am very happy with this :slight_smile:

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.