WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] wget borks if done as root for a loop script ---any clues?  (Read 3027 times)

aus9

  • Guest
Hi

TC user script works for busybox or real wget command.
When I add in my root stuff, it borks

First is the TC script
Quote
#!/bin/sh

LIST="bigreqsproto-1.1.2.tar.bz2 compositeproto-0.4.2.tar.bz2"
for Z in $LIST
do
   wget http://xorg.freedesktop.org/releases/individual/proto/$Z
done

Result (as expected) (culled output to keep it short)
Code: [Select]
sh wgettest
2013-06-09 03:02:51 (129 KB/s) - `bigreqsproto-1.1.2.tar.bz2' saved [113218/113218]
2013-06-09 03:02:53 (94.7 KB/s) - `compositeproto-0.4.2.tar.bz2' saved [101208/101208]

2) Now do it as root with a modest tweak?
Quote
#!/bin/sh

if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting."
   exit 1                                                     
fi

LIST="bigreqsproto-1.1.2.tar.bz2 compositeproto-0.4.2.tar.bz2"
for Z in $LIST
do
        su -c '/usr/local/bin/wget http://xorg.freedesktop.org/releases/individual/proto/$Z ' tc
done

Results not culled for trouble shooting.....wget is loaded BTW, script added to /tmp
Code: [Select]
sudo su && cd /tmp
sh wgettest
--2013-06-09 02:59:38--  http://xorg.freedesktop.org/releases/individual/proto/
Resolving xorg.freedesktop.org... 131.252.210.176
Connecting to xorg.freedesktop.org|131.252.210.176|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html
    [    <=>                                                                                                      ] 92,004       108K/s   in 0.8s   

2013-06-09 02:59:40 (108 KB/s) - `index.html' saved [92004]

--2013-06-09 02:59:40--  http://xorg.freedesktop.org/releases/individual/proto/
Resolving xorg.freedesktop.org... 131.252.210.176
Connecting to xorg.freedesktop.org|131.252.210.176|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.1'

    [     <=>                                                                                                     ] 92,004      47.4K/s   in 1.9s   

2013-06-09 02:59:42 (47.4 KB/s) - `index.html.1' saved [92004]

Any clues?

It looks like it does not like the Z variable but why not?

(work a round)
I could have my script start as TC or local user, then sudo su after wgets but it would be nice to know what I am doing wrong,
having only just learnt loops thanks to Rich, I was sure I had it, until nasty old root would not play ball

cheers

Gordon

### trivia, I am aware how to use wget's wget command with an extra "-O /tmp/filename" to stop root downloading the files into TC
« Last Edit: June 09, 2013, 06:00:28 AM by aus9 »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: wget borks if done as root for a loop script ---any clues?
« Reply #1 on: June 09, 2013, 12:32:06 AM »
You did not export Z, so it has no value in the su command.
The single quotes used in your su command prevent the expansion of $Z.
So either export Z or use double quotes in the su command.

aus9

  • Guest
Re: wget borks if done as root for a loop script ---any clues?
« Reply #2 on: June 09, 2013, 06:00:05 AM »
gerald_clark

Beautiful, that works well. The actual list has 24 items in it but example short list works as expected

thanks heaps

## trivia, to my eyesight quote box looks like it truncates space before \ so using a code box instead

Code: [Select]
#!/bin/sh
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting."
   exit 1                                                     
fi
su -c 'tce-load -i wget' tc
HERE=`pwd`

LIST="bigreqsproto-1.1.2.tar.bz2 compositeproto-0.4.2.tar.bz2"
for Z in $LIST
do
        su -c "/usr/local/bin/wget http://xorg.freedesktop.org/releases/individual/proto/$Z \
        -O $HERE/$Z" tc
done
« Last Edit: June 09, 2013, 06:02:06 AM by aus9 »