Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a script to an alias

Status
Not open for further replies.

visvid

Technical User
Jun 3, 2002
131
GB
I want to add a script to an alias, i have been told you create a function , however the problem is i work on a lot of boxes each day. So i have created a word pad document where i have my aliases, then i just cut/paste onto what ever box i am working on.

The alias i want is free and the command i am running is this :
for i in `vxdg list | grep -v "NAME" | awk '{print $1}'`
do
echo "$i"
vxdg -g $i free
done
but cant get alias=free' to work any ideas

visvid
 
Hi,

If you're using a c shell (csh), you can do

alias free 'pathto/free.sh'

...where 'patho' is the actual path to where free.sh (assuming a Bourne shell script) resides.

This may work in other shells as well, it's just that my default shell prompt is a c shell. (I write scripts using Bourne shells for supposed portability, however.)

But I'm wondering why not just update your bin dir with a job call free?

Also, calling an alias isn't as predictable as calling a variable, which is invoked using 'set', not 'alias'.

set free=path/free

Then, 'free' is invoked by using '$free'.

Again, this may not work either, depending on system flavor and defaults.

I say make a bin directory in your home directory with the job 'free' and make sure this bin directory is in our path variable, and call it a day.

set $path = { $path /home/username/bin }

Hope this gives you some options.

Sean aka TimeTraveler



Visit
 
I would think function is the way to go as well. But if you want it goofy, here it is

alias free="for i in `vxdg list | grep -v NAME | awk \'{print $1}\'`
do
echo $i
vxdg -g $i free
done"
 
TimeTraveler,

You have to teach us how to travel in time. I want to make a trip both way.

I would think putting those commands in a function and define the path would be a good way to go, but thought lot of people do not realize that an alias does not have to be a one liner.

Hope all well
 
Visvid,

Yet another option is..

alias free='/path/script.sh'

and make the script.sh file,
#!/bin/sh
#
for i in `vxdg list | grep -v "NAME" | awk '{print $1}'`
do
echo "$i"
vxdg -g $i free
done
#

And chmod 700 /path/script.sh

If you really want it as an alias and not a script called by an alias, then try this, I currently dont have access to a machine to verify..

alias=free'for i in `vxdg list | grep -v "NAME" | awk '{print $1}'` ; do echo "$i" ; vxdg -g $i free ; done'

I am unsure how the above alias line will look on the display, so, the alias is one line from alias= to done'
 
Hi guys many thanks for the help, as i said i work on many sun boxes so i cannot put the script on each box. However I was shown this last night which works well

alias free=_free
function _free {
for i in `vxdg list | grep -v "NAME" | awk '{print $1 }'`
do
echo "$i"
vxdg -g $i free
done
}
alias freesum=_freesum
function _freesum {
for i in `vxdg list | grep -v "NAME" | awk '{print $1 $5}'`
do
echo "$i"
FREESPACE=`vxdg -g $i free | awk '{print $5}' | grep -v LENGTH | awk '{ n+=$0}; END{print n/2048}'`
echo $FREESPACE Mb free
done
}


The idea is to create a function , which I never knew about , so i have create a notepad file on my pc then putty onto the boxes and dump this in with the other alias's

visvid
 
Try putting the function that you want into your wordpad document. It should work for the session that you paste it into, eg...

alias blah=blah
alias blah=blah
function free {
for i in `vxdg list | grep -v "NAME" | awk '{print $1}'`
do
echo "$i"
vxdg -g $i free
done
}
alias blah=blah
alias blah=blah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top