[ale] how to get bash to run .bash_profile?

cfowler cfowler at outpostsentinel.com
Mon Feb 3 09:04:17 EST 2003


Attechd is a c file.  Compile it and use it.  It should do what you want
with ease

You ought to add the BSD login() and logout() code to place data in
/var/run/utmp


On Fri, 2003-01-31 at 21:06, cfowler wrote:
> 
> Oops one more thing.  You have to redirect the output since init's STDs are on
> /dev/console
> 
> s1:2345:respawn:/bin/bash --login < /dev/tty1 1>/dev/tty1 2>/dev/tty1
> 
> 
> On 12/31/1969, "Christopher Bergeron" <christopher at bergeron.com> wrote:
> 
> >-----BEGIN PGP SIGNED MESSAGE-----
> >Hash: SHA1
> >
> >Hey guys, how do I get bash to run .bash_profile?  I'm looking at my
> >startup, and I'm trying to figure out why when I set my inittab to
> >load:  /bin/bash instead of a "getty".  When it spawn's by bash session,
> >it doesn't load my .bash_profile.  Is there a way I can load a bash
> >shell and have it subsequently execute my .bash_profile?
> >
> >Alternatively, is there a way to get a getty to log in automatically (on
> >slackware!).  For some reason, I can't get slackware to use the
> >mingetty+autologin patch/binary.  I was able to get it to work on RhAT,
> >but not on Slack8.
> >
> >Preferably, I'd like to skip "getty" altogether...
> >
> >
> >Thanks!
> >- -CB
> >-----BEGIN PGP SIGNATURE-----
> >Version: GnuPG v1.2.1 (MingW32)
> >Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> >iD8DBQE+OykYTKCy0t3zQgURAkdcAJ91SBx84EVqeavZ1/HOOQhy2SUcWgCgxUfv
> >wZS2HDYI0mkgVl2Ozs6YUo0=
> >=dFaj
> >-----END PGP SIGNATURE-----
> >
> >
> >_______________________________________________
> >Ale mailing list
> >Ale at ale.org
> >http://www.ale.org/mailman/listinfo/ale
> >
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale




/*
 *
 * Build with
 * gcc -s -o auto auto.c
 *
 * Make sure that you use the full path to the device
 *
 * Here is an example entry:
 *
 * 5:2345:respawn:/sbin/auto -u root -t /dev/tty5
 */
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <unistd.h>
#include <getopt.h>


static char *u = NULL;
static char *tty = NULL;



/*
 * Aggument processor
 */
pArgs(int argc, char **argv) {
    int opt;
    opterr = 0;

    while((opt = getopt(argc, argv, "t:u:")) > 0) {
        switch(opt) {
            case 't': tty = strdup(optarg); break;
            case 'u': u = strdup(optarg); break;
            default: fprintf(stderr, "auto -u <user> -t <tty>\n");
                     exit(1);
                
        }
    }

    if((u == NULL )) {
        u = strdup("root");
    }
       
}

/*
 * Main function
 */
int
main(int argc, char *argv[]) {
    struct passwd *p;
    int ttyFd;

    pArgs(argc, argv);

    if((p = getpwnam(u)) == NULL) {
        fprintf(stderr, "user %s does not exist!\n", u);
        exit(1);
    }

    /* If tty is not NULL then we need
     * to change our tty to the new one.  We could
     * be called from inittab
     */
    if(tty != NULL) {
        

        if((ttyFd = open(tty, O_RDWR)) == -1) {
            perror("open tty:");
            exit(1);
        }

        /* Remap our STD's */
        close(0);close(1);close(2);
        dup2(ttyFd, 0);
        dup2(ttyFd, 1);
        dup2(ttyFd, 2);
    }

    /* Change users */
    chdir(p->pw_dir);
    setgid(p->pw_gid);
    setuid(p->pw_uid);

    execl(p->pw_shell, "-sh", 0);
    perror("exec error:");
    return -1;

}


/* vi: set ts=4 sw=4 et :*/





More information about the Ale mailing list