Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: help with writing script

  1. #11
    Senior Member registered user
    Join Date
    Feb 2004
    Posts
    237

    another idea....

    I have an idea to further improve this script.....

    #!/bin/sh
    konsole -e telnet n7us.net


    This script assumes there is a valid internet connection

    I ran the script with the network cable pulled out of side of computer....it brings up the Konsole, but just sits there with blank screen.......

    Just to make the script nicer, is there a way to test for network connection, if there is, the script just runs as normal. But if there is no connection, the script just exits, and that way, you dont have a blank Konsole screen staring at you. Not that its a big deal, but I think this would be a nicer script.

    I am reading up on linux shell scripts but its hard to find the right command for the job. Would you use an if command? Not sure of syntax......bob

  2. #12
    Senior Member registered user
    Join Date
    Feb 2004
    Posts
    235
    You could use an if/then/else pair in your script. For example:

    Code:
    if eth0 up
    then exec telnet-ssl session
    else exit
    This isn't actual code but just a layout so you get the idea for error-proofing the script. The else statement catches anything that doesn't apply to the if statement, otherwise it would trigger the telnet-ssl session and exit when the session is done.


    HTH,

    Durand

  3. #13
    Senior Member registered user
    Join Date
    Feb 2004
    Posts
    237

    if/then/else

    Hello Durand......I will try what you suggested. The script i am usingis below:

    #!/bin/sh
    konsole -e telnet n7us.ne


    But where would i insert this coding? :



    if eth0 up
    then exec telnet-ssl session
    else exit


    Would I put it right after the last line in my script? I posted a separate message about getting scripting help for different things. I have also been reading the help sites on web but cannot really find what I want. I want to understand the code you suggested and learn what each line does. I will try this and post backlater my results....bob

  4. #14
    Senior Member
    Join Date
    Nov 2003
    Posts
    1,323
    Found something on the net for you:

    Code:
    #!/bin/sh
    NET=eth0
    
    if ! ifconfig | grep $NET >/dev/null 2>&1 ||\
       ! ifconfig $NET | grep UP >/dev/null 2>&1; then
     echo "Get a net!"
     exit 1
    fi
    konsole -e telnet n7us.ne
    exit 0

  5. #15
    Senior Member registered user
    Join Date
    Feb 2004
    Posts
    235
    Try this block as your script:
    Code:
    #!/bin/sh
    if [-e /etc/network/ifstate ]
    then konsole -e telnet
    else exit
    exit
    fi
    That should be all it should take. Upon perusing the other scripts with this type of block, it seems that you must end an if statement with fi. Note I inserted two exits, one to catch if the eth0 connection isn't up, and the other to terminate the script once the telnet session is done. This way you wouldn't have to create two scripts when one like this would kill two birds with one stone.

    HTH,

    Durand

  6. #16
    Senior Member registered user
    Join Date
    Feb 2004
    Posts
    237

    thanks

    thanks Duran and Markus......I will try the scripts later tonite and see what happens.....a few questions tho.....for Markus...that coding sure looks complicated! How would I go about deciphering it? I would l;ike to know what the script line by line does if possible. And Durand, in your script i didnt see a reference to the "n7us.net" that I connect with. OK i will try out ad post back tomorrow....thank you..bob

  7. #17
    Senior Member
    Join Date
    Nov 2003
    Posts
    1,323
    Hehe, As I said I found it on the net and modified just a bit, just can't get used to not declaring a variable before using it which you don't seem to have to do in bash.
    Basically it looks for the word eth0 in ifconfig and directs the stderr output to the same filedescriptor as stdout, don't ask me how: http://en.tldp.org/HOWTO/Bash-Prog-I...O-3.html#ss3.1
    If it can't find eth0 it echos a message and exits, if it finds it you get a connection and it exits afterwards.

  8. #18
    Senior Member
    Join Date
    Nov 2003
    Posts
    1,323
    Hmm, Durands approach seems a bit easier, how about:
    Code:
    #!/bin/sh
    NET=$(grep eth /etc/network/ifstate)
    
    if [ -n "$NET" ]
    then
     konsole -e telnet n7us.ne 
     exit 1
    else
     echo "Get a net!"
     exit 0
    fi
    If eth0 is found in /etc/network/ifstate NET gets the value eth0=eth0, then -n tests if the variable NET is not empty and proceeds with telnet, else echoes a message.
    Hmm again. His block is still shorter

  9. #19
    Senior Member registered user
    Join Date
    Mar 2004
    Location
    Berlin
    Posts
    436
    A different approach would be to look if n7us.net is availabĺe:

    Code:
    ping -c1 n7us.net >/dev/null 2>&1 && echo success
    or
    Code:
    ping -c1 n7us.net >/dev/null 2>&1 || exit 1
    eth0 may be up in the local net.
    may be up, but no dns-server found ...

    -c1 will only ping one time.
    >/dev/null sends the output to 'nowhere'
    2>&1 sends errormessage to the location, where the output goes ('nowhere' too)
    && (read: AND) will execute the following code only if the first command succeeded. Here you may call a script-function, if your command is too complex.

    || (read: OR [exclusive]) will execute the following command (exit 1) only, if the previous failed.
    So your code for continuing when everything is fine will just follow.

    In general, an excellent scripting guide is found here:
    http://freshmeat.net/projects/advanc...criptingguide/

    Do you want to run the script totally automated?
    If you want to login, where you have to wait for a login-prompt, you have to use 'expect' - which isn't installed on my system - why?

  10. #20
    Senior Member registered user
    Join Date
    Mar 2004
    Location
    Berlin
    Posts
    436
    (sorry - doubled 'submit'-hit)

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. writing to cd
    By sunnmoon in forum General Support
    Replies: 1
    Last Post: 06-15-2005, 04:08 PM
  2. V3.8.1 hd writing bug?
    By fmfischer in forum General Support
    Replies: 1
    Last Post: 04-14-2005, 11:07 AM
  3. Writing it to CD
    By irvine in forum The Lounge
    Replies: 4
    Last Post: 12-02-2004, 03:27 AM
  4. Writing to / and subdirs.
    By bikerman in forum General Support
    Replies: 1
    Last Post: 04-15-2004, 12:22 AM
  5. writing problem with usb pen
    By shadinio in forum Hardware & Booting
    Replies: 1
    Last Post: 03-25-2004, 09:09 PM

Posting Permissions

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


SFP TO RJ45 TRANSCEIVER SFP MODULE COPPER SFP OPTICAL PORT TO RJ45 ETHERNET PORT picture

SFP TO RJ45 TRANSCEIVER SFP MODULE COPPER SFP OPTICAL PORT TO RJ45 ETHERNET PORT

$7.99



Dell Intel X710-DA2 5N7Y5 Dual-Port 10GbE SFP+ PCIe 3.0 x8 Network Adapter picture

Dell Intel X710-DA2 5N7Y5 Dual-Port 10GbE SFP+ PCIe 3.0 x8 Network Adapter

$27.50



Cisco Acacia DP04QSDD-E25-840 400G QSFP-DD Coherent DCO Transceiver Module picture

Cisco Acacia DP04QSDD-E25-840 400G QSFP-DD Coherent DCO Transceiver Module

$699.99



NEW Sealed Cisco SFP-10G-LR 10GBASE-LR SFP+ 1310nm 10km *US Shipping* picture

NEW Sealed Cisco SFP-10G-LR 10GBASE-LR SFP+ 1310nm 10km *US Shipping*

$24.00



Genuine Cisco SFP-10G-SR 0-2415-03 10 Gigabit Transceiver picture

Genuine Cisco SFP-10G-SR 0-2415-03 10 Gigabit Transceiver

$5.40



HP 560SFP+ 10GB 2-port  PCIe NIC Ethernet ADAPTER 669279-001 w/ (2) 10GB SFP+ picture

HP 560SFP+ 10GB 2-port PCIe NIC Ethernet ADAPTER 669279-001 w/ (2) 10GB SFP+

$16.99



Intel X520-DA2 10Gb 10Gbe 10 Gigabit Network Adapter NIC Dual Port E10G42BTDA picture

Intel X520-DA2 10Gb 10Gbe 10 Gigabit Network Adapter NIC Dual Port E10G42BTDA

$28.94



Lenovo 00YK615 Intel X710-DA2 10GbE 2-port SFP+ PCI-E FC Network Adapter NIC picture

Lenovo 00YK615 Intel X710-DA2 10GbE 2-port SFP+ PCI-E FC Network Adapter NIC

$27.99



Dell 10 Gigabit SFP+ SR Transceiver 0XYD50 NEW SEALED picture

Dell 10 Gigabit SFP+ SR Transceiver 0XYD50 NEW SEALED

$24.99



Arista SFP-10G-SR 10GBASE-SR XVR-10001-20 850nm SFP+ Optical Transceiver picture

Arista SFP-10G-SR 10GBASE-SR XVR-10001-20 850nm SFP+ Optical Transceiver

$30.00