home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 2.4 Tip for Changing Account Setup: Keep a Shell Ready Chapter 2
Logging In
Next: 2.6 Use Absolute Pathnames in Shell Setup Files
 

2.5 Tips for Speeding up Slow Logins

When I first started using the C shell in the early 1980s, I made incredible .cshrc and .login files (2.2 ) with all kinds of nice customizations. Aliases, commands to check my mail, calendar systems, shell scripts in the background to watch things for me... boy, was this great! Except when I tried to log in, that is. I was working on an overloaded VAX 11/750. Logging in could take a few minutes, from when I got the ;login: prompt until I finally got my shell prompt % (...well, it was really a much fancier prompt, but that's another story :-) ).

The C shell seems (to me) to be pretty slow at reading long .cshrc and .login files - especially at setting aliases. So, I learned some ways to get logged in faster. They were especially nice when I was at someone else's terminal and needed to log in for something quick. You might not want to use these exact techniques, but I hope they'll give you some ideas if your logins take too long. The same ideas will work on other shells - but with that shell's commands and syntax, of course.

2.5.1 Quick Login

Add a "quick login" setup to the top of your .cshrc . As soon as the C shell starts and sets a few essentials, this setup asks whether you want a prompt right away. If you answer yes, it starts another C shell with the -f option (important: this makes the subshell (38.4 ) skip your .cshrc so you don't get a loop):

login: jerry


Password:
Last login: Tue Jan 21 12:34:56 PST 1985
   ...
Answer y for quick login or RETURN for standard: y


For a standard login, type 'exit 77'.
% mail bigboss


Subject: I'm on my way
Carol, I'm leaving for the meeting now. See you by 10:00.
.


% [CTRL-d]


login:

From there, I can run a few quick commands. Typing CTRL-d or exit quits the quick subshell and kills my original login shell, too. If I want to stay logged in on that terminal, I type exit  77 . That makes the quick subshell return an exit status (44.7 ) of 77; the test in the .cshrc notices this and continues logging me in, reading the rest of the .cshrc and .login .

Here's the top of the .cshrc file to set that up:


if
 ! $?
 



{ }
 

$< =~
 



kill
 $$
 



setenv
 



# only do stuff below if this is an interactive shell
if (! $?prompt) goto cshrc_end

# QUICK LOGIN:
if (! $?LOGGEDIN) then
   set path = (/bin /usr/ucb /usr/local/{bin,mh} {/usr,~}/bin .)
   echo -n "Answer y for quick login or RETURN for standard: "
   if ("$<" =~ y*) then
      echo "For a standard login, type 'exit 77'."
      csh -f
      # PLAIN "exit" JUST EXITS .cshrc... THIS IS BRUTAL BUT IT WORKS:
      if ($status != 77) kill -9 $$
   endif
endif

setenv LOGGEDIN yes

     ...Rest of .cshrc
...

cshrc_end:

CAUTION: Be sure to use an if  ($?prompt) test (2.9 ) first to keep this command from being read by noninteractive shells. If you don't, non-interactive shells for jobs like at may hang, waiting for an answer to the "quick login" question - or just be confused and not work.

2.5.2 A Second Alias and Command File

Maybe you have a set of aliases or setup commands that you use only for certain projects. If you don't need that setup every time you log in, you can put the setup commands in a separate file. Make an alias named something like setup that reads the file into your setup shell. Only type setup when you need the extra setup done.

Here's the alias:

~
 source
 
alias setup 'if (! $?setup) source ~/lib/cshrc2'

and the start of the ~/lib/cshrc2 file:

set setup  # variable to stop re-sourcing

alias foo bar
   ...

The first line in the cshrc2 file sets a shell variable that keeps the setup alias from re-reading the file into this shell. This saves time if you forget that you've already run setup .

2.5.3 Once-a-Day Setup

Maybe there are some commands that you want to run only once a day, the first time you log in. For example, I had a reminder system that showed my calendar for the day, reminded me of birthdays, etc. A test like this in .login handles that:

$date[n]
 
set
 `...`
 

-e
 
touch
 



unset
 
# Put day name in $date[1], month in $date[2], date in $date[3], etc:
set date=(`date`)
# if today's daily setup file doesn't exist, make it and do stuff:
if (! -e ~/tmp/,setup.$date[3]) then
   touch ~/tmp/,setup.$date[3]
   do_calendar
   ...Other once-a-day setup
...
endif
unset date

That test uses csh arrays (47.5 ) to get today's date and make an empty file in my tmp directory with a name like ,setup.23 . Once a file is created (say, on June 23), then the setup commands won't run again that day. I have a program that periodically removes files named with a comma(, ) (23.20 , 23.22 ) so ,setup.23 will be long gone by the next month's twenty-third day. That could also be done from the .logout file (3.1 , 3.2 ) .

- JP


Previous: 2.4 Tip for Changing Account Setup: Keep a Shell Ready UNIX Power Tools Next: 2.6 Use Absolute Pathnames in Shell Setup Files
2.4 Tip for Changing Account Setup: Keep a Shell Ready Book Index 2.6 Use Absolute Pathnames in Shell Setup Files

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System