1834554 Members
3976 Online
110069 Solutions
New Discussion

/etc/inittab question

 
SOLVED
Go to solution
David Land
Frequent Advisor

/etc/inittab question

I have a question on whether the following command will work within /etc/inittab.

4char:3:once:su - userid -c "scriptname to run"

It seems the command is not being executed when my Unix server is rebooted. I can manually run the su - userid -c "scriptname to run" and it will work fine.

Can a command like the above work within /etc/inittab?
5 REPLIES 5
John Poff
Honored Contributor

Re: /etc/inittab question

Hi,

The first field in an inittab entry, 'id', is limited to only one to four characters. Try something like '4chr' and see if that works.

JP
David Land
Frequent Advisor

Re: /etc/inittab question

Yes, I have changed it to contain only 4 characters and it still does not work.
John Poff
Honored Contributor
Solution

Re: /etc/inittab question

Ok. Have you tried putting the 'su - userid' inside of your script? Have you tried specifying the full path for the 'su' command and your script?

JP


David Land
Frequent Advisor

Re: /etc/inittab question

It looks like it worked by specifying the full command /usr/bin/su in /etc/inittab.

Thanks.
A. Clay Stephenson
Acclaimed Contributor

Re: /etc/inittab question

First, test your command from the shell by prefacing it with "exec command args" since this is what init actually does. I suspect your problem is the "su - userid" rather than simply "su userid". The "-" instructs su to source the users .profile and I suspect that this is just what you want it to do to set some environment variables. In almost all cases, .profile contains some commands like stty, tset, and tabs which expect a terminal (more accurately a tty device) as stdin. You don't have that when you exec this command from inittab and thus these commands fail. You should actually set and export all the needed variables in the script itself or better still let the user's .profile and your script source the same file that sets and exports these variables.

Normally, these tasks are put in /sbin/init.d and linked to /sbin/rc3.d/SNNNmyscript rather than using inittab.
If it ain't broke, I can fix that.