NAS326, auto execute command at startup
P13r0
Posts: 3
Hi all,
I would like my NAS326 to execute some (simple) commands at startup, but I would prefere to keep NAS' software untouched; in other words, I would prefere not to install Tweaks/Random Tools. "Since those packages exist, the standard f/w already provides a way to execute something at startup", I guess. Assuming I'm right: which is the "magic file" (...or the "magic trick") to get the job done...?
Thank you in advance for your help!
Regards
I would like my NAS326 to execute some (simple) commands at startup, but I would prefere to keep NAS' software untouched; in other words, I would prefere not to install Tweaks/Random Tools. "Since those packages exist, the standard f/w already provides a way to execute something at startup", I guess. Assuming I'm right: which is the "magic file" (...or the "magic trick") to get the job done...?
Thank you in advance for your help!
Regards
0
Accepted Solution
-
The magic trick used by Tweaks and RandomTools is that they are zypgs, installed in the normal way (apart from the MetaRepository injector), and so they are started regularly by the firmware package manager.Fortunately for you there is another way. The packages are started by /etc/init.d/zypkg_controller.sh, and this script contains this snippet:[code]ZYPKG_PKG_SRC_PATH="/i-data/.system/zy-pkgs"
<snip>
USRPKG_DEPS_START="${ZYPKG_PKG_SRC_PATH}/USRPKG_DEPS_START"
<snip>
case "$1" in
"start" )
<snip>
# - start to startup packages according to ${USRPKG_DEPS_START}
while read zypkg; do
bname=`basename ${zypkg}`
zypkg=${ZYPKG_PKG_SRC_PATH}/${bname}
Processed_Packages=${Processed_Packages}:${bname}
write_log "- starting package \"${bname}\" ..."
#ckeck ZYPKG_DEPS format
CHKVERSION=`grep "/i-data/" ${zypkg}`
if [ "$?" != "0" ]; then
PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
zypkg=${PKGVOLPATH}/etc/init.d/${bname}
fi
if [ ! -x ${zypkg} ]; then
write_log "---> Error: start-up program \"${zypkg}\" is not existed or not excutable"
else
${zypkg} startup
if [ "$?" == "0" ]; then
write_log "---> start \"${bname}\" successfully."
else
write_log "---> start \"${bname}\" failed."
fi
fi
done < ${USRPKG_DEPS_START}
[/code]So basically it reads the file /i-data/.system/zy-pkgs/USRPKG_DEPS_START line by line, each line is considered to be a filename, the directory is stripped, and /i-data/.system/zy-pkgs/ put in front. If the resulting filename is executable, it is executed with 'startup' as argument.So create an executable script in /i-data/.system/zy-pkgs/, and put it's name in /i-data/.system/zy-pkgs/USRPKG_DEPS_START (which doesn't exist by default).You can also use /i-data/.system/zy-pkgs/USRPKG_DEPS_SHUTDOWN to shutdown your stuff cleanly on nas shutdown.
0
All Replies
-
The magic trick used by Tweaks and RandomTools is that they are zypgs, installed in the normal way (apart from the MetaRepository injector), and so they are started regularly by the firmware package manager.Fortunately for you there is another way. The packages are started by /etc/init.d/zypkg_controller.sh, and this script contains this snippet:[code]ZYPKG_PKG_SRC_PATH="/i-data/.system/zy-pkgs"
<snip>
USRPKG_DEPS_START="${ZYPKG_PKG_SRC_PATH}/USRPKG_DEPS_START"
<snip>
case "$1" in
"start" )
<snip>
# - start to startup packages according to ${USRPKG_DEPS_START}
while read zypkg; do
bname=`basename ${zypkg}`
zypkg=${ZYPKG_PKG_SRC_PATH}/${bname}
Processed_Packages=${Processed_Packages}:${bname}
write_log "- starting package \"${bname}\" ..."
#ckeck ZYPKG_DEPS format
CHKVERSION=`grep "/i-data/" ${zypkg}`
if [ "$?" != "0" ]; then
PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
zypkg=${PKGVOLPATH}/etc/init.d/${bname}
fi
if [ ! -x ${zypkg} ]; then
write_log "---> Error: start-up program \"${zypkg}\" is not existed or not excutable"
else
${zypkg} startup
if [ "$?" == "0" ]; then
write_log "---> start \"${bname}\" successfully."
else
write_log "---> start \"${bname}\" failed."
fi
fi
done < ${USRPKG_DEPS_START}
[/code]So basically it reads the file /i-data/.system/zy-pkgs/USRPKG_DEPS_START line by line, each line is considered to be a filename, the directory is stripped, and /i-data/.system/zy-pkgs/ put in front. If the resulting filename is executable, it is executed with 'startup' as argument.So create an executable script in /i-data/.system/zy-pkgs/, and put it's name in /i-data/.system/zy-pkgs/USRPKG_DEPS_START (which doesn't exist by default).You can also use /i-data/.system/zy-pkgs/USRPKG_DEPS_SHUTDOWN to shutdown your stuff cleanly on nas shutdown.
0 -
Thank you so much!
I'll try, and let you know the result
Regards0 -
...It works, thank you again!
Just a note, for non expert users (...like me):
[code]
#ckeck ZYPKG_DEPS format
CHKVERSION=`grep "/i-data/" ${zypkg}`
if [ "$?" != "0" ]; then
PKGVOLPATH=`grep ${bname} ${PKGSTATUSFILE} |grep "Installed-Rule" |awk -F":" '{print $2}' |sed 's/\/$//g' |sed 's/ //g'`
zypkg=${PKGVOLPATH}/etc/init.d/${bname}
[/code]
The executable file (i.e. /i-data/.system/zy-pkgs/your_script.sh) MUST contain the string "/i-data/", otherwise the NAS will try to execute a file (tipically /etc/init.d/your_script.sh)... that doesn't exist.
A simple remark (something like: # /i-data/) is OK too.
Regards0
Categories
- All Categories
- 415 Beta Program
- 2.4K Nebula
- 151 Nebula Ideas
- 98 Nebula Status and Incidents
- 5.7K Security
- 277 USG FLEX H Series
- 277 Security Ideas
- 1.4K Switch
- 74 Switch Ideas
- 1.1K Wireless
- 42 Wireless Ideas
- 6.4K Consumer Product
- 250 Service & License
- 395 News and Release
- 85 Security Advisories
- 29 Education Center
- 10 [Campaign] Zyxel Network Detective
- 3.6K FAQ
- 34 Documents
- 34 Nebula Monthly Express
- 85 About Community
- 75 Security Highlight