Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Command line help

  • 13-08-2012 1:59pm
    #1
    Banned (with Prison Access) Posts: 1,332 ✭✭✭


    To request a URL from the web and read the result of the request, what command line programs are there available under Linux and are there any script examples of such programs?

    Bare in mind I need this to run on a DD-WRT router.


Comments

  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    I'd use wget. If you want the result printed to standard output then use wget -O - http://.....


  • Registered Users, Registered Users 2 Posts: 201 ✭✭jonathan11


    Not familiar with DD wrt but you might be able to use curl.
    curl http://eee
    -I will just give you the response code.
    curl -I http://eee
    If it is a https site you can use insecure mode
    curl -k https://eee


  • Registered Users, Registered Users 2 Posts: 863 ✭✭✭goldenhoarde


    just going to say curl but jonathon11 has it said!


  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    Don't think curl will fit on DD-WRT router but this looks like the job
    http://www.timpinkawa.net/ddwrt/wget.html


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    That is probably the version of wget I use on my ddwrt router. It actually comes with a cut down version that is part of the busybox binary, however that is missing some code to save on space (specifically I needed the ability to give a password) so I had to use the version from optware.


  • Advertisement
  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    Turns out wget is already available on DD-WRT so no install required.

    After battling with vi to write a script (brings back memories) it's straight forward enough
    #!/bin/sh
    res="$(wget -q -O - http://mysite.com/check.php)"
    
    if [ $res -eq 1 ]
    then
       echo "Do my thing"
    else
       echo "Do nothing"
    fi
    

    Just need to do this at an interval now. Maybe a loop in the script or a cron job


  • Registered Users, Registered Users 2 Posts: 1,333 ✭✭✭Saganist


    Turns out wget is already available on DD-WRT so no install required.

    After battling with vi to write a script (brings back memories) it's straight forward enough
    #!/bin/sh
    res="$(wget -q -O - http://mysite.com/check.php)"
    
    if [ $res -eq 1 ]
    then
       echo "Do my thing"
    else
       echo "Do nothing"
    fi
    

    Just need to do this at an interval now. Maybe a loop in the script or a cron job

    I would suggest a cron instead of a loop.


  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    Saganist wrote: »
    I would suggest a cron instead of a loop.

    Cron seems to be unreliable on the current build of DD-WRT.


  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    Presume OpenWRT isn't an option? It has an enormous collection of packages and seems very stable.

    I'm currently using cron and curl to upload my ip address to my website so that I can connect remotely.


  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    humbert wrote: »
    Presume OpenWRT isn't an option? It has an enormous collection of packages and seems very stable.

    I'm currently using cron and curl to upload my ip address to my website so that I can connect remotely.

    OpenWRT might be an option, need to check the hardware compatibility.

    But the solution I have at the moment seems to work fine.

    Using an infinitive while loop, which sleeps for 5mins between each loop, I'm checking a page on my website, if it returns "1", I send a WOL packet to one of the PCs on my LAN, which I can then remote into using Team Viewer.

    My script is called when the router starts, using & to run it in the background.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    OpenWRT might be an option, need to check the hardware compatibility.

    But the solution I have at the moment seems to work fine.

    Using an infinitive while loop, which sleeps for 5mins between each loop, I'm checking a page on my website, if it returns "1", I send a WOL packet to one of the PCs on my LAN, which I can then remote into using Team Viewer.

    My script is called when the router starts, using & to run it in the background.

    SSHing to the router isn't an option? (so that you can explicitly trigger the WOL packet)

    I suppose you want to keep the interface pretty high level and so avoid command line interaction.


  • Banned (with Prison Access) Posts: 1,332 ✭✭✭desaparecidos


    humbert wrote: »
    SSHing to the router isn't an option? (so that you can explicitly trigger the WOL packet)

    I suppose you want to keep the interface pretty high level and so avoid command line interaction.

    There's one other router between mine and the "internet" which I don't have control over so I find trying to get in to talk to my router or PC from the outside world impossible.

    The good thing about Team Viewer is that the connection is initialized via a global ID rather than IP addresses, so no matter how much layers the destination PC is behind, as long as Team Viewer is running and there is an internet connection, you can connect to it.

    On my website I have a simple page to change the output of check.php. Effectively an online wake button for my PC. I just change the value to "1", wait 5mins or so, then fire up Team Viewer.


  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    There's one other router between mine and the "internet" which I don't have control over so I find trying to get in to talk to my router or PC from the outside world impossible.

    The good thing about Team Viewer is that the connection is initialized via a global ID rather than IP addresses, so no matter how much layers the destination PC is behind, as long as Team Viewer is running and there is an internet connection, you can connect to it.

    On my website I have a simple page to change the output of check.php. Effectively an online wake button for my PC. I just change the value to "1", wait 5mins or so, then fire up Team Viewer.

    Ah, I made the assumption that because you could connect to your PC you must be able to connect to the router. I've never used Team Viewer but that does sound handy.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Turns out wget is already available on DD-WRT so no install required.

    After battling with vi to write a script (brings back memories) it's straight forward enough
    #!/bin/sh
    res="$(wget -q -O - http://mysite.com/check.php)"
    
    if [ $res -eq 1 ]
    then
       echo "Do my thing"
    else
       echo "Do nothing"
    fi
    
    Just need to do this at an interval now. Maybe a loop in the script or a cron job

    Thank you for post.

    I am trying do something similarly. I want to use wget with -b parameter so that the download will continue after closing the terminal window. I want to download into USB external drive of a DDWRT WL500Gpv2 router.

    I am running terminal from Ubuntu 12.04. In router I have BusyBox v1.13.4 (2011-05-17 15:55:35 CEST) built-in shell (ash) with Optware and transmission installed (into external router drive).

    I mention that wget download is working without any parameters, but when I put -b parameter i get:
    root@xyz:~# wget -b ftp.xyz.com
    wget: illegal option -- b
    

    Please advice,
    Thank you in advance.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    The version of wget that is baked into busybox has most of the less common parts removed in order to save space. So you have two options, either you can download the full version which probably does have the switch you want using optware and just use that instead, or (and this is the option I would recommend) you can just put nohup before the wget command, which will accomplish the same thing.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Knasher wrote: »
    The version of wget that is baked into busybox has most of the less common parts removed in order to save space. So you have two options, either you can download the full version which probably does have the switch you want using optware and just use that instead, or (and this is the option I would recommend) you can just put nohup before the wget command, which will accomplish the same thing.

    Thank you, I have tried with nohup before the wget command but is doesn't work. No errors, but no file downloaded, even with the terminal window opened.

    root@xyz:/mnt/Temporary# nohup wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    root@xyz:/mnt/Temporary# 
    
    
    Please, I did something wrong? Should I try the other option?

    Tks again.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    amplatfus wrote: »
    Thank you, I have tried with nohup before the wget command but is doesn't work. No errors, but no file downloaded, even with the terminal window opened.

    root@xyz:/mnt/Temporary# nohup wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    root@xyz:/mnt/Temporary# 
    
    
    Please, I did something wrong? Should I try the other option?

    Tks again.
    Not getting error messages unfortunately doesn't tell you much on ddwrt as that's another thing that is largely removed. That being said I tried the nohup command on routers with 2.4 and 2.6 kernels and both worked as expected. But if the file does download when nohup isn't used, then the fault must be on the nohup end, and I really can't think of what it might be, are you sure the directory is writable?. At this point it would probably be quicker to install wget from optware and just use that.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Knasher wrote: »
    Not getting error messages unfortunately doesn't tell you much on ddwrt as that's another thing that is largely removed. That being said I tried the nohup command on routers with 2.4 and 2.6 kernels and both worked as expected. But if the file does download when nohup isn't used, then the fault must be on the nohup end, and I really can't think of what it might be, are you sure the directory is writable?. At this point it would probably be quicker to install wget from optware and just use that.



    I am using:
    DD-WRT v24-sp2 mega (c) 2011 NewMedia-NET GmbH
    Release: 05/17/11 (SVN revision: 17084)
    BusyBox v1.13.4 (2011-05-17 15:55:35 CEST) built-in shell (ash)


    I am executing 2 commands with only difference: with nohup or without nohup. Without nohup is working at \mnt\tmp. I have file saved: Contents-i386.gz at router HDD address: \mnt\tmp. With nohup no errors but one file with 0 kb - attashed here in my post. Below are the commands run into Ubuntu 12.04 terminal connected via telnet into WL500gpv2 router (with ddwrt firmware). I did not close the terminal from start to the end of tests.
    root@xyz:~# uname -r
    2.4.37
    root@xyz:~# 
    root@xyz:~# cd /mnt/tmp
    root@xyz:/mnt/tmp# nohup wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    root@xyz:/mnt/tmp# wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz      
    Connecting to ftp.ubuntu.com (91.189.92.177:80)
    root@xyz:/mnt/tmp# nohup wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    root@xyz:/mnt/tmp# wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    Connecting to ftp.ubuntu.com (91.189.92.156:80)
    root@xyz:/mnt/tmp# ls
    Contents-i386.gz  nohup.out
    root@xyz:/mnt/tmp# 
    
    
    Could you please run:
    nohup wget http://ftp.ubuntu.com/ubuntu/dists/hardy-backports/Contents-i386.gz
    
    Also, if you have any observation/ question, please let me know.
    Thank you for being here with me.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    So the nohup.out is where stdout would normally be redirected, which obviously isn't happening here. Honestly I'd say the version of nohup in that build must be bugged. On my router running the 2.4 kernel I'm using a newer build than you, version 18946, so you could try stepping up to that instead. Either that or get a version of nohup or wget from optware instead.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Knasher wrote: »
    So the nohup.out is where stdout would normally be redirected, which obviously isn't happening here. Honestly I'd say the version of nohup in that build must be bugged. On my router running the 2.4 kernel I'm using a newer build than you, version 18946, so you could try stepping up to that instead. Either that or get a version of nohup or wget from optware instead.


    OK, I will try to update only wget or nohup from optware. If it will not work, then I will do a firmware update.

    Thank you.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    I am searching how to update nohup and wget :(
    Discovered the date of wget and nohup I run:
    BusyBox v1.13.4 (2011-05-17 15:55:35 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
    root@xyz:~# cd /usr/bin
    root@xyz:/usr/bin# ls -la /usr/bin
    …
    lrwxrwxrwx    1 root     root           17 May 17  2011 nohup -> ../../bin/busybox
    …
    lrwxrwxrwx    1 root     root           17 May 17  2011 wget -> ../../bin/busybox
    …
    root@xyz:/usr/bin# 
    
    
    


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Dear Knasher,

    I did not find the way to update wget and nohup.
    I was thinking if is a good idea to kindly ask you to share the wget and nohup files from optware (opt) folder. Please, what do you think, it will work?

    I have attashed here mine, as for refference.
    I see two options now:
    1. to replaces my opt wget and nohup files with yours, if this is possible;
    2. to update my firmware from DD-WRT v24-sp2 (05/17/11) mega - build 17084M NEWD-2 Eko to DD-WRT v24-sp2 (05/17/11) mega - build 18946M NEWD-2 Eko from ftp://dd-wrt.com/others/eko/V24_TNG/

    Please reply with you opinions and advice.
    All the best.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    Hey, sorry for not getting back to you, I was away for the last couple of days :).

    Anyway, honestly if it was me I'd probably just switch to the newer build, that is actually the version I'm running and so far I haven't had any problems with it. Plus they tend to do stable versions very infrequently so the version you are running is quite out of date at this point.

    But the choice is yours and either way should serve you fine.

    The second choice is to install them from optware. In ddwrt there are two different kinda software repositories, the default one ipkg, which doesn't contain much and then the bigger one ipkg-opt. This webpage details how to set it up just in case you weren't already aware. When you have that set up you should be just able to call "ipkg-opt install wget" and it will install it. Just be aware that you then have two wget binaries on your system so you need to make sure you are calling the right one, probably easiest to just specify the full path with /opt/bin/wget rather than changing the search path (which can get complicated if you are just different binaries compiled against different libraries).

    Nohup is part of the busybox binary and there doesn't seem to be a standalone in optware, so it is best to avoid that whole thing if you chose to go that route.

    But like I said, I'd just install the newer version if I were you.

    Also it isn't possible to send you my version of wget or nohup. This are all compiled into a large binary called busybox (hence you will notice both wget and nohup pointing towards the same place), and replacing that without properly updating the firmware could have weird results. The most I could do is send you the version of wget from optware, but honestly you are better off installing it the proper official way.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Dear Knasher.

    I am glad you are OK. Also, I am very lucky to find you here, getting the precious informations.

    Let me get to the subject, now. I have optware installed and "ipkg-opt install wget" worked and I executed already couple a days before. Below is the results for today command:
    BusyBox v1.13.4 (2011-05-17 15:55:35 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
    root@xyz:~# ipkg-opt install wget
    Package wget (1.12-2) installed in /opt/ is up to date.
    Nothing to be done
    Successfully terminated.
    root@xyz:~# 
    

    Maybe is still not working because, as you said, I have two wget binaries on my system of wget.

    Please advice me:
    1. Do you know how could I call the updated wget one?
    2. Do you know how can I update nohup?

    PS: I have spend much time configuring this firmware with optware, external usb hdd, torrents client.
    I am "afraid" to start from the begining with the updated firmware. Befause, as far as I know, at update is recommended to clear nvram. But if this will be the last option I will follow it without problem.

    Wating for 2 more advice from you :)
    Wish you all the best.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    amplatfus wrote: »
    Dear Knasher.

    I am glad you are OK. Also, I am very lucky to find you here, getting the precious informations.

    Let me get to the subject, now. I have optware installed and "ipkg-opt install wget" worked and I executed already couple a days before. Below is the results for today command:
    BusyBox v1.13.4 (2011-05-17 15:55:35 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
    root@xyz:~# ipkg-opt install wget
    Package wget (1.12-2) installed in /opt/ is up to date.
    Nothing to be done
    Successfully terminated.
    root@xyz:~# 
    

    Maybe is still not working because, as you said, I have two wget binaries on my system of wget.

    Please advice me:
    1. Do you know how could I call the updated wget one?
    2. Do you know how can I update nohup?

    PS: I have spend much time configuring this firmware with optware, external usb hdd, torrents client.
    I am "afraid" to start from the begining with the updated firmware. Befause, as far as I know, at update is recommended to clear nvram. But if this will be the last option I will follow it without problem.

    Wating for 2 more advice from you :)
    Wish you all the best.

    As I said, the choice is yours. If you have wget installed then you should be able to call it using /opt/bin/wget. If you call /opt/bin/wget --help you will get a full list of all the switches is supports, which includes the background switch you were originally looking for.
    root@linksys:~# which wget
    /usr/bin/wget      
    root@linksys:~# ls -l /usr/bin/wget
    lrwxrwxrwx    1 root     root            17 Apr  7 12:08 /usr/bin/wget -> ../../bin/busybox
    (so as you can see the default is still pointed at busybox, however under /opt/bin)
    
    root@linksys:~# ls -l /opt/bin/wget
    -rwxr-xr-x    1 root     root        422544 Feb 16  2012 /opt/bin/wget
    (as you can see this is the version you want to use)
    root@linksys:~# /opt/bin/wget --help 
    [...tons of text...]
    (and you should see the background switch)
    

    If you still need nohup for another reason, then it is part of the coreutils package in optware and after install you can call it in a similar manner to wget.

    Finally if you want to be able to call wget and have it link to the right one without having to type the /opt/bin thing every time, then the best way of doing that I think is setup an alias in the profile file. You need to save this as a part of a startup script in ddwrt as the home directory is in ram and will be reset upon restart.
    echo "alias wget='/opt/bin/wget'" > /tmp/root/.profile
    
    After that then the next time you login you should be able to call wget and it will refer to the right one.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Dear Knasher,

    All is working like I need it. Thank you for all advices.
    You save me :) and made my dreams come true!

    I have the same results as you. I modified my own startup script. Now is working like a charm. I can put my own codes here, but are the same like yours :) Finnaly. Thank you for patient and for all! For my needs, right now nohup not need it. In future, when I will have problems....I will update my firmware too. I have them downloaded ~ from when was available.

    Sorry for misspeled word in my posts before.
    I owe give you a beer. I am a happy user.
    Wish all the best to you Knasher. Hope that will help others too.


  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    No problem at all, glad to hear you got it working.


  • Registered Users, Registered Users 2 Posts: 9 amplatfus


    Knasher wrote: »
    No problem at all, glad to hear you got it working.

    Hi Knasher,

    Hope you are OK. Just to let you know that I will never forget your help :)

    All the best to you and to this form :)


Advertisement