Log in

Bekijk de volledige versie : tcl exec problem



KGy
22-05-2007, 11:23
Hi. Sorry my english.

I want run this cmd from tcl:



wget http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/wget_1.10.2-3_mipsel.ipk >/opt/tmp/wget.log 2>&1

(wget = busybox_wget)

My tcl code:


set WGET_BIN [ file join / opt bin wget ]
set WGET_LOG [ file join / opt tmp wget.log ]
...

exec $::WGET_BIN $::URL >$::WGET_LOG 2>&1

Problem: ">/opt/tmp/wget.log" forwarding not working and "2>&1" too.

I use http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/ and don't want change to oleg-optware (http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/) . I must use busybox_wget.

Thank, George

KGy
22-05-2007, 12:09
I found on net:



exec $::WGET_BIN $::URL >&$::WGET_LOG


Thanks, George

al37919
23-05-2007, 06:28
Nice that you've already found solution yourself. I just want to mention that tcl distribution on the router contains rich documentation located in 'n' section of man pages:
man n exec

KGy
23-05-2007, 10:44
Hi, al37919!

Sorry my english.
Have you got web-console for your chech.wget.tcl script? (Add link to wget.list)

Thanks, George

al37919
23-05-2007, 16:41
Sorry, George, no. I'm quite happy with it running as background daemon, and watch it using ssh, ftp, or samba.

KGy
23-05-2007, 20:54
Hi, al37919!

Sorry my english.

I found a problem in your check.wget.tcl script.
If CurrentUrl not http or ftp url, the wget (I use busybox@wget) write messages:


wget: not an http or ftp url: NOT_URL

Your code not check this case, not delete this false item from list.



#Check if URL is not found
#Check if URL is not HTTP or FTP url
set rule "^.*ERROR 404.*Not Found.*"
if {[regexp $rule $Out] || [regexp {not an http or ftp url} $Out]} {
for {set i 0} {$i < [llength $lList]} {incr i} {
if {[lindex $lList $i] eq $CurrentURL} {
set lList [lreplace $lList $i $i]
incr i -1
}
}
ListToFile $::WGET_LIST $lList
set f [open $::WGET_LIST_NOT_FOUND a]
puts $f $CurrentURL
close $f
....


Sorry, if your oleg-optware-cross-stable wget not response this messages (and remove item from list your tcl script), but I use busybox@wget.
If I use oleg-optware-cross-stable packages in ipkg.conf, I can't use some programs (nano, screen, etc.)
I try to use some programs from optware (amule, wget) but not run my system.
I check this by file utility:


[admin@MYROUTER bin]$ file amuled
amuled: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), stripped
[admin@MYROUTER bin]$ file ipkg
ipkg: ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), dynamically linked (uses shared libs), stripped
[admin@MYROUTER bin]$


Bye,
George

al37919
23-05-2007, 23:24
If CurrentUrl not http or ftp url
OK, I agree, I just haven't met such condition yet :) So, I updated my script to include response for such case from external wget which I'm using, and your version for built in wget.


If I use oleg-optware-cross-stable packages in ipkg.conf, I can't use some programs (nano, screen, etc.)
That's really strange, because nano and screen are working just fine with optware/oleg feed. Just a guess: after switching to optware you must first install ipkg-opt and uclibc-opt (and then probably reinstall everything)

I try to use some programs from optware (amule, wget) but not run my system.
They can't run on unslung system, because unslung and optware use different set of the libraries to be built with. With optware/oleg amuled and rtorrent work just fine.

I think you should make an effort and finally switch from obsolete unslung feed to the modern optware. Moreover, AFAIK the optware will be the default feed starting from the Oleg's firmware ver.8.
Regards, al.

KGy
29-05-2007, 10:04
Hi al37919!

Sorry my english.

I write 3 cgi-script:

wgetdlist - list wget.tcl download, completed and not_found list, add link field and button (, and my wget.tcl log (start service, start dn, end dn, complete (move to completed dir :) ), etc))

wgetdaddlink - add http or ftp link to download list file...

wgetdstartstop - start service if stopped or stop or started...

I use busybox@httpd service from /opt/share/wwwstatus/cgi-bin dir,
copy these files to your cgi-bin dir, change path to your .tcl and ../tmp/.. in cgi scripts (sorry: my script include my path and file names:) ) and use : myip:myport/cgi-bin/wgetdlist (192.168.0.254:8080/cgi-bin/wgetdlist.)

My scripts include link to /cgi-bin/status script: I write this script on based oleg's forum "run two webserver" topic and create some sript to (start/stop samba, cron, sctcs(seaky's ctcs), al37919's wgetd :) , stupid-ftpd, run sh command (based on oleg asus webconfig page...)



[admin@MYROUTER cgi-bin]$ cat wgetdlist
#!/bin/sh
echo "Content-type: text/html"
echo
echo "<html>"
echo "<head>"
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" >"
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" >"
echo "<meta http-equiv=\"Refresh\" content=\"300\">"
echo "<title>WebStatus</title>"
echo "</head>"
echo "<body bgcolor=#5555aa link=#000000 vlink=000000>"
echo "<h2>System info for Asus home gateway router</h2>"
echo "<hr><a align=center href=/cgi-bin/status>Back</a><hr>"
echo "<b>Add link to al31919's wgetd.tcl daemon download list:</b>"
echo "<form method=\"post\" action=\"wgetdaddlink\">"
echo "<table>"
echo "<td><input type=\"text\" maxlength=\"256\" size=\"120\" name=\"AddLink\" value=\"\"></td>"
echo "<td><input type=\"submit\" value=\"Add link\"></td>"
echo "</table></form>"
echo "<hr>"
echo "<b>al31919's wgetd.tcl daemon - download list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch /opt/share/samba/wgetd/wget.list
cat /opt/share/samba/wgetd/wget.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al31919's wgetd.tcl daemon - completed list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch /opt/share/samba/wgetd/wget.completed.list
cat /opt/share/samba/wgetd/wget.completed.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al31919's wgetd.tcl daemon - 404 not found or not http or ftp link list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch /opt/share/samba/wgetd/wget.not_found.list
cat /opt/share/samba/wgetd/wget.not_found.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al31919's wgetd.tcl daemon - log:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"8\" wrap=\"off\" readonly=\"1\">"
touch /tmp/wgetd.log
cat /tmp/wgetd.log
echo "</textarea></td>"
echo "</table>"
echo "<hr><a align=center href=/cgi-bin/status>Back</a><hr>"
echo "</body>"
echo "</html>"




[admin@MYROUTER cgi-bin]$ cat wgetdaddlink
#!/bin/sh
cat > upload.$$
cat << __FLUSH
Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">

<title>WebStatus</title>
</head>
<body bgcolor=#5555aa link=#000000 vlink=000000>
<h2>System info for Asus home gateway router</h2>
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
__FLUSH
URL=`cat upload.$$ | sed -e 's/ /_/g' -e 's/%3A/:/g' -e 's/%2F/\//g' -e 's/%7E/~/g' -e 's/+/ /' -e 's/^AddLink=//g' \
| awk '{print $1}'`
if [ "$URL" == "" ]; then
echo "<br>URL is empty. Not added to list<br>"
else
echo $URL >>/opt/share/samba/wgetd/wget.list
echo "<br>$URL added to list<br>"
fi
rm upload.$$
cat << __FLUSH
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
</body>
</html>
__FLUSH




[admin@MYROUTER cgi-bin]$ cat wgetdstartstop
#!/bin/sh
echo "Content-type: text/html"
echo
echo "<html>"
echo "<head>"
echo "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\" >"
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" >"
echo "<title>WebStatus</title>"
echo "</head>"
echo "<body bgcolor=#5555aa link=#000000 vlink=000000>"

if [ `ps | grep -c "tclsh8.4 /opt/share/wgetd/wgetd.tcl"` -gt 1 ]
then
for i in "/opt/etc/init.d/[sS]99wgetd" ; do
$i stop >/dev/null
done
echo "<br>wgetd daemon stopped...<br>"
else
for i in "/opt/etc/init.d/[sS]99wgetd" ; do
$i start >/dev/null
done
echo "<br>wgetd daemon started...<br>"
fi
echo "<a align=center href=/cgi-bin/status>Back</a><br>"
echo "</body>"
echo "</html>"


and some files, to use busybox@httpd


[admin@MYROUTER root]$ cd /opt/etc
[admin@MYROUTER etc]$ cat webst.conf
#!/bin/sh
WEBST_HOST=localhost
WEBST_HTTP_PORT=8040
WEBST_HTTP_USER=user
WEBST_HTTP_PASSWORD=passwd
WEBST_WGETD=/opt/share/samba/wgetd

[admin@MYROUTER etc]$ cat webst_httpd.conf
A:*
/cgi-bin:user:passwd

[admin@MYROUTER etc]$ cat init.d/S99webst
#!/bin/sh
# Based on Oleo transmission_watchdog script for Transmission Package
. /opt/etc/webst.conf

PATH=/sbin:/bin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin

BUSYBOX_HTTPD=/usr/sbin/busybox_httpd
HTTPD_CONF=/opt/etc/webst_httpd.conf
WEBST_WEB_LOCATION=/opt/share/wwwstatus

create_httpd_conf() {
cat > ${HTTPD_CONF} << __EOF
A:*
__EOF
if [ ! -z "${WEBST_HTTP_USER}" ]; then
echo "/cgi-bin:${WEBST_HTTP_USER}:${WEBST_HTTP_PASSWORD}" >> \
/opt/etc/webst_httpd.conf
fi
}

start() {
if [ ! -x "${BUSYBOX_HTTPD}" ]; then
echo "busybox httpd ${BUSYBOX_HTTPD} not started."
exit 2
fi
create_httpd_conf
echo "Starting busybox httpd at port ${WEBST_HTTP_PORT} ... "
${BUSYBOX_HTTPD} -c ${HTTPD_CONF} -p ${WEBST_HTTP_PORT} -h \
${WEBST_WEB_LOCATION}
echo "done"
}

stop() {
echo "Shutting down busybox httpd... "
kill `ps | grep "/opt/etc/webst_httpd.conf" | grep -v "grep" | \
awk '{print $1}' `
echo "done"
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: $0 (start|stop|restart)"
exit 1
;;
esac


And I add your .tcl script some log functions (log to system log, to wgetd.log (use web pages), to console (for debug .tcl...): use 1 values for log



....
set WGET_PARTIAL [file join $WGET_BASE partial]
set WGET_COMPLETED [file join $WGET_BASE completed]

set SYSLOGD [file join / tmp syslog.log]
set WGETDLOG [file join / tmp wgetd.log]

set LSYSLOGD 1
set LWGETDLOG 1
set LCONSOLE 1
...




....
set DATE [string range [exec date] 4 18]
if {$LSYSLOGD==1} {
exec echo $::DATE wgetd: start download: $FileName >>$::SYSLOGD
}
if {$LWGETDLOG==1} {
exec echo $::DATE wgetd: start download: $FileName >>$::WGETDLOG
}
if {$LCONSOLE==1} {
puts "wgetd: start download: $FileName"
}
# exec $::WGET_BIN $CurrentURL -b -c -P $::WGET_PARTIAL -o $::WGET_LOG
if {[catch {exec $::WGET_BIN $CurrentURL -P $::WGET_PARTIAL >&$::WGET_LOG} result]} {
}
set DATE [string range [exec date] 4 18]
if {$LSYSLOGD==1} {
exec echo $::DATE wgetd: end download: $FileName >>$::SYSLOGD
}
if {$LWGETDLOG==1} {
exec echo $::DATE wgetd: end download: $FileName >>$::WGETDLOG
}
if {$LCONSOLE==1} {
puts "wgetd: end download: $FileName"
}
....
etc


And I create sh script for add link from ssh console:
/usr/local/addlink


#/bin/sh
if [ "$1" = "" ]; then
echo "Usage: $0 URL"
else
echo $1 >>/opt/share/samba/wgetd/wget.list
fi

Simple but working...under windows:cool:
get link from IE or Firefox or others...
select link and copy to clipboard...
write to console: "addlink " and paste LINK mouse right button from clipboard...and press enter

George

al37919
15-06-2007, 08:58
Hi, George!
I just returned from... Budapest :) , where I was during last three weeks. Beautiful city.

You did a very nice work. Based on the feedback from other people I updated slightly my main code to include several bugfixes.

KGy
15-06-2007, 10:15
Hi (and sorry my english)
I modified a cgi-script (added download list function)
al37919: I'm very sorry a change your nick :o

George

[admin@MYROUTER cgi-bin]$ cat wgetdlist


#!/bin/sh
. /opt/etc/webst.conf

echo "Content-type: text/html"
echo
echo "<html>"
echo "<head>"
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" >"
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" >"
echo "<meta http-equiv=\"Refresh\" content=\"300\">"
echo "<title>WebStatus</title>"
echo "</head>"
echo "<body bgcolor=#5555aa link=#000000 vlink=000000>"
echo "<h2>System info for Asus home gateway router</h2>"
echo "<hr><a align=center href=/cgi-bin/status>Back</a><hr>"
echo "<table><form method=\"post\" action=\"wgetdaddlink\">"
echo "<tr><td><b>Add link:</b></td>"
echo "<td><input type=\"text\" maxlength=\"256\" size=\"120\" name=\"AddLink\" value=\"\"></td>"
echo "<td><input type=\"submit\" value=\"Add\"></td></tr>"
echo "</form>"
echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"wgetdaddlist\">"
echo "<tr><td><b>Add list:</b></td><td>"
echo "<input type=\"file\" maxlength=\"256\" size=\"120\" name=\"AddList\" value=\"\">"
echo "</td><td><input type=\"submit\" value=\"Add\"></td>"
echo "</tr></form></table>"
echo "<hr>"
echo "<b>al37919's wgetd.tcl daemon - download list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch ${WGETD_BASE}/wget.list
cat ${WGETD_BASE}/wget.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al37919's wgetd.tcl daemon - completed list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch ${WGETD_BASE}/wget.completed.list
cat ${WGETD_BASE}/wget.completed.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al37919's wgetd.tcl daemon - 404 not found or not http or ftp link list:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"4\" wrap=\"off\" readonly=\"1\">"
touch ${WGETD_BASE}/wget.not_found.list
cat ${WGETD_BASE}/wget.not_found.list
echo "</textarea></td>"
echo "</table>"
echo "<b>al37919's wgetd.tcl daemon - log:</b><br>"
echo "<table>"
echo "<td><textarea cols=\"118\" rows=\"8\" wrap=\"off\" readonly=\"1\">"
touch /tmp/wgetd.log
cat /tmp/wgetd.log
echo "</textarea></td>"
echo "</table>"
echo "<hr>"
echo "<table>"
echo "<b>${WGETD_BASE}</b> `df ${WGETD_BASE} | awk 'NR==2 {print ", "$3" bytes ("substr($5,0,length($5)-1)"\%) used, "$4}'` bytes free"
echo "</table>"
echo "<hr><a align=center href=/cgi-bin/status>Back</a><hr>"
echo "</body>"
echo "</html>"


[admin@MYROUTER cgi-bin]$ cat wgetdaddlink


#!/bin/sh
. /opt/etc/webst.conf
cat > uplink.$$
cat << __FLUSH
Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Refresh" content="5; url=/cgi-bin/wgetdlist">
<title>WebStatus</title>
</head>
<body bgcolor=#5555aa link=#000000 vlink=000000>
<h2>System info for Asus home gateway router</h2>
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
__FLUSH
URL=`cat uplink.$$ | sed -e 's/ /_/g' -e 's/%3A/:/g' -e 's/%2F/\//g' -e 's/%7E/~/g' -e 's/+/ /' -e 's/^AddLink=//g' \
| awk '{print $1}'`
if [ "$URL" == "" ]; then
echo "<br>URL is empty. Not added to list<br>"
else
echo $URL >>${WGETD_BASE}/wget.list
echo "<br>$URL added to list<br>"
fi
rm uplink.$$
cat << __FLUSH
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
</body>
</html>
__FLUSH


[admin@MYROUTER cgi-bin]$ cat wgetdaddlist


#!/bin/sh
. /opt/etc/webst.conf
cat > uplist.$$
cat << __FLUSH
Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Refresh" content="5; url=/cgi-bin/wgetdlist">
<title>WebStatus</title>
</head>
<body bgcolor=#5555aa link=#000000 vlink=000000>
<h2>System info for Asus home gateway router</h2>
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
__FLUSH
LST=`cat uplist.$$ | grep -c "tp://"`
if [ "$LST" = "0" ]; then
echo "<br>Download list is empty or not include any valid links. Not added to list<br>"
else
cat uplist.$$ | tr -d "\r" | grep "tp://" >>${WGETD_BASE}/wget.list
echo "<br>Download list [$LST item(s)] added to list<br>"
fi
rm uplist.$$
cat << __FLUSH
<hr><a align=center href=/cgi-bin/wgetdlist>Back</a><hr>
</body>
</html>
__FLUSH


And a config file with some definitions:
[admin@MYROUTER cgi-bin]$ cat /opt/etc/webst.conf


#!/bin/sh
WEBST_HOST=localhost
WEBST_HTTP_PORT=8040
WEBST_HTTP_USER=
WEBST_HTTP_PASSWORD=
WGETD_BASE=/opt/share/samba/wgetd

Remarks:
WEBST_HOST=hostname
WEBST_HTTP_PORT=port number
WEBST_HTTP_USER=
WEBST_HTTP_PASSWORD=
WGETD_BASE=path_to_wget_base_dir

The WEBST_xxxx definitions not required to cgi-scripts. I use it define some parameters to busybox@httpd service based on sctcs service (by seaky) and "How to run two webservers" topic.