More mason madness happening. Debugged some things I found wrong with, well, everything. I also *finally* added commenting. Thread support was also added (yay recursion).
Feel free to, well, post comments!
Thu, 25 Dec 2003Whew! More updates.
More mason madness happening. Debugged some things I found wrong with, well, everything. I also *finally* added commenting. Thread support was also added (yay recursion).
Feel free to, well, post comments!
Comments: 0 (view comments)
bourne (sh, ksh, bash, zsh, ...) file descriptor fun
Yeah, so having just figured this out now (I'm sure it's in a manpage somewhere) -
You can open file descriptors at will by doing: exec 3> file_output The 3 here is the number of the file descriptor, and can be any number really. What this lets you do now is write to that file descriptor: echo "Hello there" >&3 Now, if you look at the contents of file_output you'll see that it contains "Hello there" - neat?
To close a file descriptor do this: exec 3>&- again, where 3 is the number of the file descriptor you want to close.
Comments: 0 (view comments)
poor man's netcat.
This script requires ksh. It makes use of a feature of ksh (zsh supports this too, but differently) called a co-process. A co-process is started by using the
|& pipe at the end of a command. The file descriptor you use to write to is >&p. To read from it, you use <&p. Here's an example:
tr 'a-z' 'A-Z' |& echo "hello there" >&p exec 3>&p; exec 3>&- cat <&p The output is: HELLO THERE WTF?! You might be confused, I was when I first started playing with these. What happens is it runs tr 'a-z' 'A-Z' in the background as a
co-process. Then it echos "hello there" to the input of tr. To
signify that we are in fact done sending input, we have to close the input file
descriptor, this is done through 2 statements: exec 3>&p - this
opens file descriptor 3 and has it output to the co-process. The next
statement, exec 3>&-, tells ksh you want to close file
descriptor 3, which in turn closes the input to the co-process. The last line
should be fairly obvious: cat <&p - it sends the output of the
co-process through cat. Ok, so you want that script do ya? Look below. #!/bin/ksh [ $# -ne 2 ] && echo "Invalid parameters" && exit 1 telnet $1 $2 |& cat <&0 >&p sed -e '1,3d' <&p I won't get into much detail as to how things work here, should be pretty straight-forward. It takes 2 parameters, first being the host and second being the port. It reads from standard input and outputs to standard output.
Comments: 0 (view comments)
|
Search this siteNavigationMetadataHome About Resume My Code (SVN)ArticlesARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work EfficiencyProjectsfex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scriptsPresentationsYahoo! Hack Day '08 Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials SSH Tunneling (Video)Tag CloudCalendar
FriendsBarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler ShieldsTechnorati |
|||||||||||||||||||||||||||||||||||||||||||||||||