Using variables to spice up your login scripts

Although login script commands enable you to create reasonably powerful scripts, login script variables let you accomplish even more. John Sheesley explains what login script variables are and how you can use them to spice up your login scripts.

In the Daily Drill Down, "Creating login scripts on your NetWare server," I introduced you to several common login script commands. Using the commands discussed in that Daily Drill Down, you can create some reasonably powerful scripts. However, you can accomplish even more with login scripts if you use login script variables. In this Daily Drill Down, I’ll show you what login script variables are and how you can use them to spice up your login scripts.

What are login script variables?
As you may remember from Algebra class in high school, variables are expressions that allow you to substitute different values into equations and produce different results. Likewise, login script variables allow you to produce different results and reactions in your login scripts as the values for the variables change.

Login script variables can stand for user properties such as the user’s name. They can also return values that contain information about the user’s workstation, like the workstation’s operating system or network card MAC address. You can also use variables to return time values, including the exact time of day, or a time period, such as morning or evening.

Login script variables are always used in conjunction with the login script commands I discussed in "Creating login scripts on your NetWare server." When used with the proper login script commands, variables can give your login scripts lots of pizzazz and flexibility.

What login script variables can I use?
Novell created many different login script variables that you can use in your scripts. Novell leveraged the flexibility in NDS to allow you to create variables based on almost all object properties. It also provides a base stock of variables that you can use. Login script variables fall into six basic categories: Date, Time, User, Network, Workstation, and Miscellaneous.

Date variables
As the name suggests, date variables allow you to substitute date information in your login scripts. These variables enable you to create commands that can occur yearly, monthly, or even on specific days of the week. Common date variables you can use include:
  • DAY—This variable represents the day number of the month. Valid values for this variable are from 01 through 31.
  • DAY_OF_WEEK—This variable represents the day of week. It returns the actual name of the day.
  • MONTH—This variable returns the number of the month, not its name. The values used for this variable are 01 through 12.
  • MONTH_NAME—This variable represents the actual name of the month.
  • NDAY_OF_WEEK—This variable represent the day number of the week. Valid values are 1 through 7, where 1 represents Sunday.
  • SHORT_YEAR—This variable represents the last two digits of the year.
  • YEAR—This variable represents all four digits of the year.

Time variables
Time variables are similar to date variables in that they enable you to create login scripts that occur or display time values. However, time variables enable you to more finely break down timed events. You can break events down to the second if you desire. Time variables can also be more general, describing general times of day. Common time variables you can use include:
  • AM_PM—This variable returns the value of AM or PM depending on the time of day.
  • GREETING_TIME—This variable returns an approximate time of day. The values for this variable can be morning, afternoon, or evening.
  • HOUR—This variable represents the hour value using a 12-hour clock. The valid range for this variable is 01 through 12.
  • HOUR24—This variable represents the hour value using a 24-hour clock. The valid range for this variable is 00 through 23, where 00 represents midnight.
  • MINUTE—This variable represents the minute value on the clock. The valid range of this variable is 00 through 59.
  • SECOND—This variable represents the second value on the clock. The valid range of this variable is 00 through 59.

User variables
User variables enable you to personalize your login scripts. You can pull values from NDS and display them on the screen, or use them to cause specific events to occur. Using user variables, you can have your login scripts react to individual users or groups of users. Common user variables you can use include:
  • FULL_NAME—This variable represents the value of a user ID’s FULL_NAME property that’s stored in NDS. It’s the value that you put in the Full Name field for the User object in NetWare Administrator.
  • LAST_NAME—This variable comes from the Last Name field in the User object in NDS.
  • LOGIN_CONTEXT—This variable returns results based on the context in the NDS tree where the user logs in.
  • LOGIN_NAME—This variable returns the user’s login name. If the user has a long login name, it's truncated to eight characters by the login script.
  • MEMBER OF group—This variable is used in conjunction with a group name. It’s used to verify whether a user is a member of a certain group. It’s used most often with the IF…THEN command.
  • NOT MEMBER OF group—This variable is used in conjunction with a group name. It’s used to make sure a User object is not a member of a certain group. It’s used most often with the IF…THEN command.
  • PASSWORD_EXPIRES—This variable returns the number of days before a password expires.
  • USER_ID—This variable represents a unique number that NDS assigns to each user.

Network variables
You probably won’t use network variables very often—if at all—in your login scripts. They enable you to create login scripts that react to the environment of your network. Network variables you can use include:
  • FILE_SERVER—You’ll use this variable to represent the name of your NetWare file server.
  • NETWORK_ADDRESS—This variable represents the IPX external number of your network.

Workstation variables
Workstation variables focus on the workstation that the user is logging into. A user can have different experiences when logging into the network depending on which machine they use. You can cause your login scripts to do different things depending on the workstation’s machine type or operating system. You can even identify specific machines by using their network card’s MAC address. Common workstation variables include:
  • MACHINE—This variable returns the type of computer that the workstation is. The default value for this variable is IBM_PC.
  • OS—This variable returns the type of operating system the workstation is running.
  • OS_VERSION—This variable returns the version of the operating system that's running on the workstation.
  • P_STATION—This variable returns the MAC address of the workstation's NIC.
  • PLATFORM—This variable returns the workstation's operating system platform. You’ll probably use it more than the OS variable. Options include DOS, OS2, WIN (Windows 3.x), WNT (Windows NT), and W95 (Windows 9x).
  • SMACHINE—This variable is like the MACHINE variable, but returns a shorter version. The default value for the variable is IBM.
  • STATION—This variable returns the workstation's connection number to the server.
  • WINVER—This variable returns the version number of the workstation’s Windows OS. It’s similar to the OS_VERSION variable.

Miscellaneous variables
Miscellaneous variables aren’t built-in variables in NetWare. Instead, these are variables that the login script processor pulls from external sources. These variables may come from DOS, NDS, or command line options. Several miscellaneous variables you can use include:
  • DOS environment variable—You can use any DOS environment variable such as PATH or PROMPT in your login scripts. To do so, you must enclose the DOS variable in angle brackets [<>]. If you want to use a DOS environment variable in the MAP, COMSPEC, or FIRE PHASERS commands, you must place a percent sign [%] in front of the variable.
  • %N—You can use the %N variable with executables that accept multiple values such as LOGIN.EXE. To use the variable, you replace N with a number that represents the positional value within the command. For example, %1 would return the value JOHNS for the command LOGIN JOHNS.
  • NDS Property—You can use any NDS property value with the WRITE command as long as you precede it with a percent sign. If the property value includes a space, enclose the name in quotation marks.

Rules for login script variables
Using login script variables can occasionally be confusing. If you’ve just glanced through some of the login script examples that come with NetWare, it may appear as if the rules for variables are variable themselves. However, that’s not the case.

One of the most confusing concepts is determining when you precede a variable with a percent sign [%] and when you don’t. As a general rule of thumb, you’ll use the percent sign with a variable if you’re using the variable in the WRITE command. Otherwise, you use the variable name by itself. For example, in the WRITE command, you’d type WRITE “Welcome to the Network %LOGIN_NAME”. Conversely, in the IF…THEN command you’d type IF LOGIN_NAME = JSHEESLEY THEN.

You should also make sure that you place all variables in uppercase. If you use lowercase values, the login script processor may not properly recognize the variable. In that case, your login scripts won’t work properly, if they work at all.

Login scripts can be very useful tools for your network. They enable you to control your end users' environment and automatically perform many tasks. In NetWare, Novell provides you with many commands that allow you to create powerful login scripts. Login script variables give added flexibility to NetWare’s login script commands. In this Daily Drill Down, I’ve shown you several of the common variables you can use in your login scripts.
If you have any login scripts on your network that you think would be useful to others or that you think are particularly creative, e-mail them to us. We’ll share them with other subscribers to TechRepublic in future Daily Drill Downs. Make sure that you send them in flat ASCII format. Also, be sure to include detailed documentation about the purpose of the script and how you’ve used the commands.

John Sheesley has been supporting networks since 1986, when he got his hands on NetWare 2.2. Since then, he’s worked with the Jefferson County Police Department in Louisville, KY and the Genlyte-Thomas Group. John’s been a technical writer for several leading publishers, including TechRepublic, The Cobb Group, and ZDJournals. If you’d like to contact John, send him an e-mail .

The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

Editor's Picks

Free Newsletters, In your Inbox