I originally posted this in the wrong forum, so I hope I don't get ripped apart for a double post. As part of my new job, I'm learning a little shell scripting, working on an HP-UX system.

I'm trying to automate a user account creation process, and I need to access the template file that SAM uses so I can set certain attributes of the user's account, according to the template file. (I know, why not just use SAM? That's the same question I asked my boss, ask him. I don't know.)

Here is a sample of the template file, called /var/sam/ug/templates/ts:


handle 1 {
list UG_TS_UT 1 {
UG_TS_UT {
UG_TS_UT_TITLE = "MyTemplate";
UG_TS_UT_DESC = "User of MyTemplate";
UG_TS_UT_HDPATH = "/home";
UG_TS_UT_SUP = "/bin/tcsh";
UG_TS_UT_PGRP = "users2";
UG_TS_UT_ALTSTR = NULL;
UG_TS_UT_BOOTSU = "NO";
UG_TS_UT_PWDFSGP = "DFT";
UG_TS_UT_PWDFSGC = "DFT";
UG_TS_UT_PWDFSGL = "DFT";
UG_TS_UT_PWDFUSP = "DFT";
UG_TS_UT_PWDFERR = "DFT";
UG_TS_UT_PWDFNUL = "DFT";
UG_TS_UT_PWDFLEN = -1;
UG_TS_UT_PGID = 108;
UG_TS_UT_UIDVAL1 = NULL;
UG_TS_UT_UIDVAL2 = NULL;
UG_TS_UT_LOGENV = NULL;
UG_TS_UT_UIDMETH = 1;
UG_TS_UT_INCCOM = 1;
UG_TS_UT_ACCACT = 1;
UG_TS_UT_ALTTYPE = 1;
UG_TS_UT_ACCLFTM = -1;
UG_TS_UT_MAXPOI = -1;
UG_TS_UT_UNSUCLT = -1;
UG_TS_UT_PWDAGING = -1;
UG_TS_UT_PWDTBC = -1;
UG_TS_UT_PWDEXPT = -1;
UG_TS_UT_PWDWARN = -1;
UG_TS_UT_PWDLFTM = -1;
UG_TS_UT_PWDOPT = 2;
UG_TS_UT_CRHD = 1;
UG_TS_UT_PSD = 1;
};
};
};

Now, if any of you use HP-UX, you'll know that SAM uses the parameters set in this file to create user accounts according to this template, which is called "MyTemplate".

But how can I use these parameters? They don't look like variables, because you can't have spaces before or after the equal sign with variables. So what is this type of script called, and how can I call it in my script to use those values?

sorry this is long, I hope I made sense.

Alright, I finally found out that the script is simply a perl script. It's just a bunch of sub-routines naming variables. I was thinking it was a shell script, that's why I was so confused. So now how can I call this file from my shell script, specify the correct sub-routine, then grab the variables from this file to use in my script?

I was just told by someone else that this is not perl. Now I don't know what it is. Please help! All I need to do is know how to grab these variables and use them in my shell script!

Try

sed -e '/[\{\}]/d' -e 's/ = /=/' -e 's/;$//' filename > tmpFile
. tmpFile
rm -f tmpFile

That will turn all those lines with = signs into variables and source them, cleaning up afterwords.

This article has been dead for over six months. Start a new discussion instead.