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

damunzy

recovering former mod
Retired Moderator
Joined
Oct 29, 2000
Messages
4,981
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?
 
Argh, no *NIX scripters here? Damn.
 
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.
 
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:
 
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.
 
Back
Top Bottom