1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

*NIX shell scripting (tcsh, csh, ksn, bash, and even windows batch welcome)

Discussion in 'Computer Talk' started by damunzy, Mar 18, 2003.

  1. damunzy

    damunzy recovering former mod Retired Moderator

    Joined:
    Oct 29, 2000
    Messages:
    4,978
    Gender:
    Male
    Location:
    NJ, USA
    I have been using Solaris 8 systems a lot lately and have been writing some minor scripts to speed up some common tasks. The latest script I have done finds out the IP address of the system you telneted from and then sets the DISPLAY enviroment to that IP address in csh. Why would I want to do this? Because I telnet into this system from my windows system - on my windows system I have an XServer running (Exceed) and this sends the graphical display to pop up on my system.

    The script:
    Code:
    #!/bin/csh
    
    setenv DEV         `tty | awk -F// '{printf("%-0s%-0s%-0s",$3,"/",$4)}'`
    setenv DEVLINE     `who | grep $DEV | awk -F\( '{print $2}' | awk -F\) '{print $1}'`
    if (( DEVLINE == :0 ) || ( DEVLINE == :0.0 )) then
    setenv DISPLAY     ${DEVLINE}
    else
    setenv DISPLAY     ${DEVLINE}:0.0
    endif
    
    The way I have the script set up with the if statement solves the problem of running this script from the console (sitting at the actual computer) but doesn't fix the problem of someone telneting from computer A to B and then finally C. If you run this script it tries to send the X window to computer B and not A.....anyone know how I can solve this problem?
     
  2. damunzy

    damunzy recovering former mod Retired Moderator

    Joined:
    Oct 29, 2000
    Messages:
    4,978
    Gender:
    Male
    Location:
    NJ, USA
    Argh, no *NIX scripters here? Damn.
     
  3. Padma

    Padma the Inbond Administrator Supporter

    Joined:
    Dec 10, 2001
    Messages:
    14,407
    Location:
    Omaha, Nebraska USA
    Sorry, munzy. I haven't done any serious *NIX scripting for several years. And then, I was using ksh and/or bash in preference to csh. :)
     
  4. damunzy

    damunzy recovering former mod Retired Moderator

    Joined:
    Oct 29, 2000
    Messages:
    4,978
    Gender:
    Male
    Location:
    NJ, USA
    I use ksh also, just more familiar with csh. The ksh mini-script I do a lot is:
    Code:
    #!/bin/ksh
    while [ 1 == 1 ] ; do clear ; ls -alF ; sleep 2 ; done
    
    Just to make sure that something is being downloaded into a directory or that the TAR really is uncompressing. :)

    Got any other short little scripts that you can remember from the days when you used them? I am always interested in other people's shortcuts.
     
  5. gonzo_for_civ

    gonzo_for_civ Chicken Walker Retired Moderator

    Joined:
    Oct 6, 2001
    Messages:
    3,136
    Gender:
    Male
    lol munzy, not to insult anyone, but the most you usually see here are C++ or VB or Java scripters, and the C++ are becoming FAR rarer these days.

    Good ol' *NIX scripting just isn't appreciated these days.

    Of course I'd help ya, but that would be too similar to work, so I'll pass ;)

    BTW, in the script in question, are you telnetting from the same computer each time? If so, does it have a static IP? If that's the case..you could probably save a little time by skipping a few things.....:mischief:
     
  6. damunzy

    damunzy recovering former mod Retired Moderator

    Joined:
    Oct 29, 2000
    Messages:
    4,978
    Gender:
    Male
    Location:
    NJ, USA
    The IPs are static but I want this to be useful for people that are using computers other than mine. I sometimes also telnet from my computer, into a server, then from that server into another - this basically breaks the script as it thinks I am originating from the first server and the X Window never opens. I have added an extra if statement that filters out certain names (the names of the servers) and their IPs.

    @Gonzo: No offense taken me. I thought I would try and see if anyone here is interested in *NIX scripting, or actually any scripting since it is easier to see results compared to programming and compiling.
     

Share This Page