[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cobalt-users] Automated commands



>>       This may sound a bit stupid but I am looking for a way
>> to automate certain functions I do.
>
>There are no stupid questions.  Not that this didn't
>give me a giggle....
>
>> lets say I wanna automate this function and probably others
>>
>> /usr/bin/makemap hash /etc/virtusertable < /etc/virtusertable
>
>Launch a text editor and paste in the text between
>START and END.
>
>=-=-=-=-=-=-=-=-=-=-=-START=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>#!/bin/sh
>#
># Hash virtusertable
>#
>/usr/bin/makemap hash /etc/virtusertable < /etc/virtusertable
>=-=-=-=-=-=-=-=-=-=-=-=END-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>and then save the file as, say /usr/bin/makemehash.
>
>Somebody else can tell you where it should go exactly.
>
>> So lets say I am at the command prompt and I just type
>> makemehash it then
>
>You'll need to change the permissions to make it executable;
>chmod u+x makemehash should do the trick.
>
>NB compared to the DOS world that the current directory is *not*
>in the path.  If you have the executable in your current directory
>you'll need to type ./makemehash.
>
>Look in, say /etc/rc.d/rc3.d (on the Qube at any rate) to look
>at lots and lots of very important scripts.
>
>Next week - Mysteries Of Crontab, or, How To Make It Happen
>In Your Sleep.

Now there *is* one other option, and that is to make aliases of long
complex commands in .bash_profile.
the syntax is *really* simple, all that is required is that you remember
the shorthand. Using the above example (and suggesting my own shorthand
for the present moment)

alias mhv="/usr/bin/makemap hash /etc/virtusertable <
/etc/virtusertable"
A few simple rules:
1.
If you don't know all of the cryptic command line tools, try (as a user
first) running [from the example above] the abbreviation to see if you
get an ouptput...in this case mhv comes up blank since it means nothing
and isn't a tool either. If you don't get output and the shorthand makes
sense, use it.
2.
There is *no space* between the = and the opening parens " so this
mhv="blah" is dead right
If you forget to close the parens either of two things will happen:
	a) at next login (or a refresh of the file but we'll get to that in a
moment)shell will complain of an error in the .bash_profile and spit out
a line number. Starting at the top of the file count down until you're
at the line and examine your alias...chances are you've left the closing
parens out. I made a coment in mine several years ago every few lines in
the alias section until it sank into my thick skull.
#####"Don't forget, close quote marks on an alias statement like this"
	b) if shell *doesn't* complain at a subsequent login, when you run the
supposed alias command, it simply won't work.

Refreshing (or making shell re-read the .bash_profile)
After you've made a change, it is not necessary to log out and back in
again. Instead do this to make shell re-read in its parameters:
[17:03:43 loofah@beast]$ . .bash_profile
In phonetic terms, that's "dot [space].bash_profile...then watch what
happens!!!
This might be simpler than writing shell scripts, but you can't cron an
alias whereas you can cron a shell script. The possible reasons for this
are if short-term you need to cut down on typing long commands in, but
don't see long-term you'll need them after "this" operation, then use
aliases. If this is a repetitve or regularly-occurring periodic funtion
like makemap hash...well, consider a shell script instead.

Just another approach in the Unix collection of tips 'n tricks.

Hope This Helps!
Regards,
-Colin (Ô-Ô)
--
Colin J. Raven