Find the answer to your Linux question:
Results 1 to 9 of 9
my problem: i made an script to publish my current server ip (my provider uses dynamic ips) on a website. the script works fine starting it manually, but don't as ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2004
    Posts
    5

    script problem - acts different :?


    my problem:


    i made an script to publish my current server ip (my provider uses dynamic ips) on a website. the script works fine starting it manually, but don't as a cronjob.

    destribution: debian (knoppix 3.4)

    script:
    #! /bin/bash
    # ftp-script
    rm -f /data/currentip.html
    echo "<html><body><font face='Tahoma' color='green' style='font-size: 10pt'><u>Derzeitige Server IP:</u>

    <font color='black' style='font-size: 8pt'>" >> /data/currentip.html
    /sbin/ifconfig ppp0 > /data/ip
    /bin/cat /data/ip | /bin/grep inet | /bin/sed 's/.*Adresse:\([0-9\.]*\) .*/\1/g' >> /data/currentip.html
    echo "


    PuTTY Client</body></html>" >> /data/currentip.html
    cp /data/currentip.html /var/www/currentip.html
    result (started manually):
    Derzeitige Server IP:

    217.225.115.133

    PuTTY Client
    result (started as a cronjob):
    Derzeitige Server IP:

    inet addr:217.225.115.133 P-t-P:217.5.98.61 Mask:255.255.255.255

    PuTTY Client
    any ideas?

    jens

  2. #2
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Thats a litte wierd, it seems like your regexp doest get applied when you execute it from cron.

    Try to change this line
    Code:
    /bin/cat /data/ip | /bin/grep inet | /bin/sed 's/.*Adresse&#58;\&#40;&#91;0-9\.&#93;*\&#41; .*/\1/g' >> /data/currentip.html
    Witch this:
    Code:
    /bin/cat /data/ip | grep "inet addr" | grep Bcast | cut -d "&#58;" -f2 | cut -d " " -f1
    Which is a little simplier....and see whats happend. Also check to output file for ifconfig from cron and from a manual run to see if the differs.
    Regards

    Andutt

  3. #3
    Just Joined!
    Join Date
    May 2004
    Posts
    5
    that's my ifconfig ppp0 output (manually+cronjob):
    ppp0
    Protokoll:Punkt-zu-Punkt Verbindung
    inet Adresse:217.225.115.133 P-z-P:217.5.98.61 Maske:255.255.255.255
    UP PUNKTZUPUNKT RUNNING NOARP MULTICAST MTU:1492 Metric:1
    RX packets:349881 errors:0 dropped:0 overruns:0 frame:0
    TX packets:394153 errors:0 dropped:0 overruns:0 carrier:0
    Kollisionen:0 Sendewarteschlangenlänge:3
    RX bytes:215823975 (205.8 MiB) TX bytes:278545283 (265.6 MiB)
    it's german, so your command line can't work that way. i replaced inet addr with "inet Adresse" and Bcast with "Maske".

    result manually: just perfect
    result cronjob: no ip output in currentip.html

    thanks anyway

  4. #4
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Ok

    Try this then....its should work

    Code:
    /bin/cat /data/ip | grep "inet Adress" | grep Maske | cut -d "&#58;" -f2 | cut -d " " -f1

    Try to execute it by hand and by cron to see if it results the same....or if it workes better...
    Regards

    Andutt

  5. #5
    Just Joined!
    Join Date
    May 2004
    Posts
    5
    hmm, replace "inet Adresse" with "inet Adress"? I don't notice any other change. Result is the same like in my third post .

  6. #6
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    But if you run my command on the /data/ip file that looksl like this

    Code:
    ppp0 
    Protokoll&#58;Punkt-zu-Punkt Verbindung 
    inet Adresse&#58;217.225.115.133 P-z-P&#58;217.5.98.61 Maske&#58;255.255.255.255 
    UP PUNKTZUPUNKT RUNNING NOARP MULTICAST MTU&#58;1492 Metric&#58;1 
    RX packets&#58;349881 errors&#58;0 dropped&#58;0 overruns&#58;0 frame&#58;0 
    TX packets&#58;394153 errors&#58;0 dropped&#58;0 overruns&#58;0 carrier&#58;0 
    Kollisionen&#58;0 Sendewarteschlangenlänge&#58;3 
    RX bytes&#58;215823975 &#40;205.8 MiB&#41; TX bytes&#58;278545283 &#40;265.6 MiB&#41;
    You should get :217.225.115.133

    I thought that was your issue??
    Regards

    Andutt

  7. #7
    Just Joined!
    Join Date
    May 2004
    Posts
    5
    äh yes, but your 2nd post was nearly the same like my 2nd (i changed your command line from your first post for german output before), so i was confused .

    however, i should get 217.225.115.133. and i do! but only manually.
    the cronjob don't get any ip. very strange

  8. #8
    Just Joined!
    Join Date
    May 2004
    Location
    San Antonio, TX
    Posts
    49
    Quote Originally Posted by fraxx
    however, i should get 217.225.115.133. and i do! but only manually. the cronjob don't get any ip. very strange
    Possibly stating the obvious, but what user are you when you run this manually? Crontab (at least the versions I've played with) runs as a default low-level user if you don't include a sudo or the like, and so perhaps that low-level user in your dist doesn't have permissions to check this?

    HTH,
    Ewan

  9. #9
    Just Joined!
    Join Date
    May 2004
    Posts
    5
    hmmm good idea!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •