Empty wtmpx on Solaris

This article is a how to empty or remove /var/adm wtmpx  from a Solaris system.

In case you have same spare space to create an intermediate wtmpx before you empty the existing one follow the procedure below:

# /usr/lib/acct/fwtmp < /var/adm/wtmpx > /tmp/wtmpx.bak
# cat /dev/null > wtmpx
# gzip /tmp/wtmpx.bak
# mv /tmp/wtmpx.bak.gz /var/adm/wtmpx.`date +%Y%m%d`.gz

In case there is no space left and you cannot do a thing to release some temporary space just do

# cat /dev/null > wtmpx

view files permissions in octal format

I was wondering which is the way to list file’s permissions in octal format. I tried to find out how to do it, using ls, but I conclude that a way to do it is to use stat command:

stat -c '%A %a %n' file

Solaris 10 – create an init script

First of all, we need to understand the procedure of the boot in Solaris. Next, follows a description of the boot sequence in Solaris.

Overview of the boot sequence in Solaris

  • When Solaris boots up, it runs “init”.
  • “init” looks in /etc/inittab to find out what runlevel it needs to boot into
    On Solaris, this is normally runlevel 3. On Linux, it is normally runlevel 5.
  • “init” reads a list of the programs it needs to start at each run-level from /etc/inittab
  • On Solaris, init runs both “/sbin/rc2” and “/sbin/rc3”. On Linux, init runs only “/etc/rc.d/rc 3”.
    Notice that on Solaris, there is a separate script for each runlevel, but on Linux there is only one script and it is passed a single argument telling it what run-level to process.
  • “/sbin/rc2” (“/etc/rc.d/rc 3” on linux) does the following:
    • reads a list of all the shell scripts matching the pattern /etc/rc2.d/K* (/etc/rc.d/rc3.d/K* on linux) and runs each of those programs with the single argument “stop”.
    • reads a list of all the shell scripts matching the pattern /etc/rc2.d/S* (/etc/rc.d/rc3.d/S* on linux) and runs each of those programs with the single argument “start”.
  • On Solaris, after “/sbin/rc2” is complete, init runs “/sbin/rc3” which does a similar thing, running the K* and S* scripts in /etc/rc3.d with the single arguments “stop” and “start” respectively.

A common technique for system administrators is to use a common location for application and services startup scripts. This location is  “/etc/init.d” (/etc/rc.d/init.d on Linux).

Each script is capable of taking a single argument, which can be either “start” or “stop”.
Based on the argument passed, the script “does the right thing” to stop or start an application or service.

I have made a template for startup scripts, and I use it whenever I need to make a startup script

——————– Template of startup script ——————————————-

case $1 in 
# put startup command(s) here 
# put shutdown command(s) here 
echo "Usage: $0 start|stop" >&2 
exit 1 
exit 0

——————–End of Template —————————————

I copy this template to the directory /etc/init.d/ with a name which defines the application. For example I used a name dnssvc for a startup script for multiple dns services.

Now, we need this shell script to be executed each time the system boots. We can choose to have the “init” program run this command in run-level 2 or run-level 3. I arbitrarily chose run-level 3, which means that I need to link the program from /etc/init.d into /etc/rc3.d.

Here is the command that I used:
# ln -s /etc/init.d/dnssvc /etc/rc3.d/S93dnssvc

The letter S defines that is a startup Script. If we wanted to write a Stop Script we should have named the link starting with the letter K. The number after the S letter gives the priority of the execution. A lower number means earlier execution at boot time. Two scripts can have the same number, and there is a deterministic way of execution but there is no way to explain it.