About John Storta, Jr. Expertise I am a Sun Certified Solaris Administrator. I can answer virtually any question relating to the administration of Sun servers. I have experience installing hardware, managing user accounts, maintaining file systems, setting up backup and recovery plans, configuring Veritas NetBackup, and general troubleshooting.
Experience I have been a UNIX System Administrator for 5 years. I have implemented 5 systems as a Project Leader. I have seen a wide range of problems over the years and found solutions for all of them.
Organizations Independant Computer Consultants Association
Education/Credentials Sun Certified Solaris Administrator
Training in Oracle SQL and Veritas NetBackup
30+ university level Computer Science credits
Awards and Honors Received outstanding service award for my achievements
Recognized by VP and CEO following system implementation
User info:
Complete Solaris/Unix novice. Please forgive me if some of my terminology is not correct.
:(
1)
I have created a "script" (is that the correct word?) to execute some basic commands for a user. I enabled it using chmod u+x scriptname. Most of the script works fine, but using the "cd" command
does not seem to have a premanent effect. Here's an example:
#!/bin/csh
echo "Evaluating your directory setup...";
set dv1=0;
set dv2=0;
#See if sim/ already exists in oper/
if (-d 'oper/sim') then
set dv1=1;
endif
#Create a sim/ directory if necessary
if ($dv1 == 1) then
echo "Your sim/ directory already exists";
else
echo "Creating a sim/ directory for you";
cd oper;
mkdir sim;
cd ../;
endif
#See if backup/ already exists in ../
if (-d '../backup') then
set dv2=1;
endif
#Create a backup/ directory if necessary
if ($dv2 == 1) then
echo "Your backup/ directory already exists";
else
echo "Creating a backup/ directory for you";
cd ../;
mkdir backup;
cd oper;
endif
#CAN'T GET THIS LINE to WORK
cd $home/$USER/base/oper/sim/;
exit 0;
How do I get a "script" for a user, as above, to make a change of working directory permanent? It
seems that when the script exits, the user is always where they started. Similarly, I can not
figure out how to set an environment variable or an alias that is retained after exit from the
script.
Another question I have is not of a technical nature. I purchased a SunBlade 100 workstation last month to try to learn how to work in a Solaris environment. It arrived with the OS and several "extras" pre-installed (such as StarOffice). It also came with a "software companion" CD-ROM, with various utilities on it. When I tried to install it, the installer gave a "Java out-of-memory" error and hung there. After killing the process, I later discovered that a directory named opt/ is now missing. Trying to run StarOffice (and other software) gives an error about not being able to find the opt/ directory, and it is indeed not existant.
Anyway, after 3 weeks of phone calls to Sun tech support and Sun sales, it seems nobody I've reached knows how to tell me what to do to restore the machine to it's delivered state.
Do you know anyone at Sun who may be able to help?
It seems hard to believe that nobody there can find this information. Todays tech contact told me that she checked 4 new SunBlade 100 machines, and that all 4 had different opt/ directory contents! I did not order any specific software - what it arrived with was supposed to be "standard" for that machine. It's a disappointment that Sun has been unable to resolve this for me in 3 weeks.
Thank you very much for any help and/or advice you can offer.
Steve
Answer First of all, script is the correct term.
Is there a reason you are using the c shell? It is not very common any more. Most people use the korn(ksh) shell. it really doesn't matter, just personal preference and syntax.
I do all of my work in the korn shell, but this should apply regardless.
When you run a shell script, you are basically creating a separate environment for it to run in. Kind of like a user logging in. It takes all of the current environment settings and then does it's thing, and then exits. Since it was in it's own environment, nothing outside of it's environment was changed. That is why the variables won't export and the directories won't change. They were part of the scripts environment, not yours.
If you are familiar with C or C++, think of functions. You pass values to the functions and do all kinds of manipulation on them, yet when the function exits, none of your changes are there. That is because you only passed the values and not the actual variables. This is very similar.
To solve this problem, you need to tell the script to run in your environment and not to create it's own. You do this by sourcing the script rather than running it.
In csh, you would run the script using the source command. For example.
# source scriptname
where scriptname is the name of the script. It doesn't even have to be executable.
In ksh, you use a period in the same way.
For example.
$ . scriptname
Be sure the path to the script is correct in both instances.
If you want users to be able to run this script without using the source or . , setup an alias in the .profile or .login if your using csh.
I don't remember the syntax for setting up an alias in csh, but in ksh it would look like this.
alias aliasname='. scriptname'
Remember that scriptname should be the full path to the script, not a relative path.
I also noticed that you used a lot of relative paths in your scripts. That can be dangerous, because you assume that the user is in a certain directory. It is best to use absolute paths.
I think that covered your first question.
As for as your second question.
I never like things to be pre-installed. It is inevitable that there is going to be something that I don't like about the configuration. I would imagine that they gave you the actual CDs for everything. If so, I would recommend installing everything from scratch and try to start over.
I have had many dealings with Sun. Some good, some bad. It is really a crap shoot. I don't have any particular cure for the problem. :-(
Let me know if you need more information.
Thanks,
John Storta, Jr.
Sun Certified Solaris Administrator
Member ICCA
Perspective Systems
www.perspectivesystems.50megs.com