Script calling by inittab

Hi to all ,
i wrote a small script and i add it to inittab to start the script during Startup. The script works fine , if i call it from the prompt but if it is call from inittab it is runnng too but it does not recognize system variable like USER , LOGNAME.

Since i running out of ideas i put inside the script source /.cshrc and source /etx/profile and source/etc/enviornment.
But this does not change anything the System variable still unkown

thanks a lot for your help

BTW
i running on AIX 4.3.2.0

Those variables are set during user login and thus are only available in a user session.
During startup, no login shell is executed and no user is logged in (although root might be the owner of the startup processes). So, referring to those variables doesn't make any sense.

Does your crontab provide the @reboot time/date specifier?

1 Like

To help you, we'd have to know a bit more about the script...
Who do you think runs the script in /etc/inittab ?

Let's say it must be oracle, and as we all kmow, oracle will not run like that, it needs loads of env variables set. Is it the case? as of course e.g. LOGNAME cannot be found as the script is launched by ? at boot time, so how do you expect that specific variable to be initialised when no login occured?...

In most cases it the use of su that solves the problem like using

su -c user4thisapplication /opt/application/somebinary

In case when you need the same environment as in interactive mode ( login) you can use su - <user> at the condition you modified the .profile or whaterver profile you are using to bypass what is not used for batch mode : all that has to do with terminal settings etc... when in batch mode.

1 Like

Hi RudiC,
Thanks a lot for your reply
Sorry that i do not have much knowledge with AIX , I was not aware that this variables not available at boot up
I will come back to you when I am back in the office to answer your question
Thanks for your help
Kind regards

---------- Post updated at 08:15 PM ---------- Previous update was at 08:06 PM ----------

Hi VBE,
Thanks for your reply
I did add the call to my script with mkittab and it works but the problems is with the variables
When I am back in office I will try your recommendation with su
I was expecting it will use root as user
when I login as user root the script works perfect
When back in the office I will post the script and the entry i made in inittab
Thanks for your support
With kind regards

te/httpdlite.conf >/dev/console 2>&1
 : httpd:2:once:/cae1/3rdparty/bin/apachectl start >/dev/null 2>&1
 imqss:2:once:/usr/IMNSearch/bin/imq_start >/dev/console 2>&1
 : adsm::once:/usr/tivoli/tsm/client/ba/bin/dsmc sched > /dev/null 2>&1 #Adsm sc\
 heduler
 sserver:2:wait:/etc/mfg/rc.sserver > /dev/null 2>&1
 tty17:2:off:/usr/sbin/getty /dev/tty17
 tty18:2:off:/usr/sbin/getty /dev/tty18
 ssa:2:once:/simstatus/simstatus

when ich check it it is running with user root acount

root 13170 1 0 Jan 06 - 8:42 csh /simstatus/simstatus

---------- Post updated at 10:25 PM ---------- Previous update was at 10:09 PM ----------

Hi RudiC,

yes my crontab provide the Option @reboot , but i guest it will the same Problem that the user don''f have his full enviornment because it is in Batch mode. At the Moment it hat the call for my script in inittab , but i will try to put it now in crontab.

Kind regards
Thomas

OK, so at least we have established you are using AIX. Care to tel us which version? Issue:

oslevel -s

to display it. Please post the output.

You should - under absolutely no circumstance - use csh at all. csh is bug-ridden to the extreme and is long deprecated, not to mention non-POSIX. Is there any factual reason why the script is in csh (other than "i didn't bother to learn any other)?

I hope this helps.

bakunin

1 Like

Hi Bakunin
Thanks a lot for your reply
I did post the oslevel already at my first post it is AIX 4.3
Thanks for your nice recommendation not to use the c shell ,I don't matter which shelll I am using as long I got the variables when I am in batch mode
That is the only thing I am care about
With kind redgards
Nadielosabra

You are right, sorry. That was an oversight on my part.

OK. Can you post the script you have trouble with? Because, honestly, i have written scripts and put them in inittab before and i didn't encounter your problem, so i suspect it is something within your script rather than your system. (Albeit with a system which is ~16 years old (IIRC) one never can be sure. 4.3.2 was not even the latest 4.3-system. That should be 4.3.3 ML12.).

I hope this helps.

bakunin

1 Like

Given that /etc/inittab is a system file that could be replaced during an upgrade (okay, so you probably won't be patching AIX 4) I would suggest it is a bad place to put things. Assuming it has the line marked rc, then a better place to put things would be in /etc/rc.d/rc2.d (or whatever is the default run-level marked in /etc/inittab)

The files in there starting with a capital S are run with the parameter start when moving into that run-level. Have a look at a few to see how they are generally written. You will probably find that they are linked (hard or soft) to /etc/init.d and there are often comparable K scripts which are called when stopping a service.

The files are executed in sequence that they are found, so S20inet runs before S95Oracle or whatever you have defined.

You can put all sorts in here. They are generally Bourne Shell scripts, but you can override this with the usual #!/bin/ksh or even #!/bin/csh in the first line. You can then go on and set up your environment and fire up the code you really want.

Does that help? Generally you would use S99myscript so that all other processes to do with mounting filesystems, starting services etc. have all completed before you try to do your stuff.

Don't worry about AIX 4 either. It's not too long ago that I eventually retired an AIX 3.2.5 server :o
We moved the applications to AIX 4.3.3 :wink:

Robin

1 Like

You may add this at the beginning of /etc/profile

# Environment used in interactive mode is to be defined here
case "$0" in
-ksh | -sh)                             # add here the shells used seen in /etc/passwd
        if [[ $- = *i* ]]; then
               # printf "\033]0;`uname -n`\007" this can be used if terminalX ..
              # so you add here all you use...
             set -o vi
             stty erase ^?
            export PS1="$(hostname):\$PWD \$ "
      fi
esac

but if its only one user the concern then modify its own .profile

1 Like

Hi bakunin
the script it is running on AIX 4.3.2.0 .
the script itself work fine only when try to check the Status of few variables there are the Problem. What i found out on few comment in the Forum is the AIX makes a different betwenn lookin in interactive mode and in Batch mode.
i wrote just 3 lines of code for Troubleshooting just write te result of the command env in to a file .
And if i now compare the file i got from Batch mode and from interactive mode they are quit different.
And that is my Problem during Batch Login not all variables available.

Thanks a lot for your help , wish you a nice Weekend
With Kind regards

UNIX doesn't have a "batch mode" exactly, the question is what login or daemon ran it and what environment variables are set to what value.

No, but the shell does: there is a difference between interactive and non-interactive mode.

Being started from /etc/inittab it was init obviously. :wink:

The question is if /etc/environment already existed like it does nowadays (this is an AIX specialty, a file with "var=value"-type declarations which are set into any starting process' environment), i am just not sure when it was introduced. Next question (if it does exist and does the same as today) is what its content is.

Apart from that, i suggest to create a ksh-function setting a "standard-environment" and source that in in every script you write. This way you are not relying on some environment the parent process of a script might or might not bring.

I hope this helps.

bakunin