|
|
#1 |
|
Prospect
Join Date: Mar 2002
Location: Omaha, NE
Posts: 44
|
Complex alias in bash
I was online with my dialup connection and found things running really slowly. I decided it was time to do a restart, and iTunes announced to me that someone was connected to my shared iTunes library! At home on my Airport network I've just left this on, for the sake of others in the house who want to connect from time to time, but I'd never come across who sniffed my iTunes library over the dialup before.
Anyway, in perusing the hints, I found one that lets me see who is connected (I'd like to know next time), and this is the code: Code:
netstat -f inet -W | awk '$4 ~ /3689/ {print "iTunes connection from: "$5}' \
| sed -e 's/\.[^.]*$//g'
Code:
alias itunesshare="netstat -f inet -W | awk '$4 ~ /3689/ {print "iTunes connection from: "$5}' \
| sed -e 's/\.[^.]*$//g'"
(There was a downloadable script on that hint page, but it was from May 2003, and the link is no longer valid).
__________________
Steven Weyhrich Apple II History http://apple2history.org |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
3 possibilities
1) escape the embedded single quotes with backslashes: \'
2) make this into a bash "function" instead of an "alias". Aliases are intended only for relatively simple things. 3) make it a bash script by saving the command (not the alias) to a file, making the first line #!/bin/sh and making the fiel executable. |
|
|
|
|
|
#3 | |||||||||||||||||||
|
Prospect
Join Date: Mar 2002
Location: Omaha, NE
Posts: 44
|
Re: 3 possibilities
So I put that line in my first message in a file by itself, with the first line of the file being the "#!/bin/sh", and the second line the command. Where do I put such a file, and how do I make it executable?
__________________
Steven Weyhrich Apple II History http://apple2history.org |
|||||||||||||||||||
|
|
|
|
|
#4 |
|
Major Leaguer
Join Date: Sep 2002
Location: Earth
Posts: 381
|
Where to put the file ???
Well most UNIX people create a dir in their home folders called: bin mkdir bin then edit your path to include this directory..or just call the file directly now to make it executable: chmod is ya friend here chmod 755 <filename> Will do the trick so now to run the file ~/bin/<filename> the ~ is replaced automatically with ya home folder path... Cheers, --Zed
|
|
|
|
|
|
#5 | |||||||||||||||||||
|
Major Leaguer
Join Date: Dec 2002
Posts: 441
|
Re: bash script
To be a bash script, shouldn't the first line be #!/bin/bash (I know bash is used to provide /bin/sh under Panther, but you don't want to impose Bourne shell limitations on yourself unnecessarily...) |
|||||||||||||||||||
|
|
|
|
|
#6 | ||||||||||||||||||||||||||||||||||||||
|
Prospect
Join Date: Mar 2002
Location: Omaha, NE
Posts: 44
|
Thanks, that worked.
I notice it works either way. Why is either necessary, and why would one be preferred?
__________________
Steven Weyhrich Apple II History http://apple2history.org |
||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#7 |
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,334
|
the `#!` operator tells the operating system to execute the following code with the specified program. `/bin/sh` is the path to the original Bourne shell interpreter. `/bin/bash` is the path to the Bourne Again SHell. If you write a perl program, you set it to `/usr/bin/perl` or wherever perl is on your computer.
Your script is simple enough that it will run under sh, bash, tcsh or almost any other shell. More complex scripts are not so flexible. |
|
|
|
|
|
#8 |
|
Prospect
Join Date: Mar 2002
Location: Omaha, NE
Posts: 44
|
Thanks for the explanation. As always, the answer and associated comments have been educational!
__________________
Steven Weyhrich Apple II History http://apple2history.org |
|
|
|
![]() |
|
|