[comp.sys.next] Login Dimmer

jkight@sinai.umd.edu (Jeff Kight) (12/21/90)

I received numerous responses for my dimlogin script so...

Following is the script/executable that I use to see if anyone is
logged onto the console, and if not...dim it

There is an example crontab entry for executing dimlogin every 15 minutes

Note: the code that actually dims the screen was hacked from bright.c
      by John W.Garnett.

------------------------------------------------------------------------------
Jeff Kight                                                 jkight@umd5.umd.edu
Information Services                                        jkight@umdd.bitnet
Computer Science Center                              uunet!umd5.umd.edu!jkight
University of Maryland                                          (301) 405-3014


------------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	dimlogin
#	dim.c
#	makefile
# This archive created: Wed Dec 19 15:28:38 1990
export PATH; PATH=/bin:$PATH
if test -f 'dimlogin'
then
	echo shar: will not over-write existing file "'dimlogin'"
else
cat << \SHAR_EOF > 'dimlogin'
#!/bin/csh -F
#
#   dimlogin: by Jeff Kight  jkight@umd5.umd.edu / jkight@umdd.bitnet
#
#   general usage: executed by root (root owns /dev/evs0)
#
#   example usage: executed by cron
#
#   sample crontab entry: 0,15,30,45 * * * * root /usr/local/adm/dimlogin
#
#   purpose: checks for process Console Daemon, if not found, dim screen to 0
#
#   note: for current scripts, install dimlogin in /usr/local/adm and
#                                      dim in /usr/locbal/bin
#
#   disclaimer: use at your own risk
#
set pflag=`ps -aux | awk 'BEGIN { flag="false" } /Console Daemon/ && $0 !~ /- k/ { flag="true" } END { print flag }'`

if ($pflag == 'false') then
/usr/local/bin/dim 0
endif
SHAR_EOF
chmod +x 'dimlogin'
fi # end of overwriting check
if test -f 'dim.c'
then
	echo shar: will not over-write existing file "'dim.c'"
else
cat << \SHAR_EOF > 'dim.c'
/*
   dim.c: hacked from bright.c by John W.Garnett

   features removed: return to previous brightness setting after return

   general usage: dim [0-61]

   example usage: dim 52

   purpose: sets the screen to desired brightness

   compile using: cc bright.c -o dim

   relevant manual pages: evs and ioctl

   disclaimer: no claims are made as to the suitability of this software for
     any purpose.  use at your own risk.
*/

#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <nextdev/evsio.h>

#define EVS_DEVICE "/dev/evs0"

/* open the event status device (see man page for evs) */

int openEvs()
{
	int fd;

	fd = open(EVS_DEVICE,O_RDWR,0660);
	if (fd < 0) {
		fprintf(stderr,"error: couldn't open %s\n",EVS_DEVICE);
		exit(2);
	}
	return(fd);
}

/* set brightness to level */

int setBrightness(level)
unsigned long level;
{
	int fd;

	fd = openEvs();
	ioctl(fd,EVSIOSB,&level);
	close(fd);
}

int main(argc,argv)
int argc;
char **argv;
{
	unsigned long request;

	if (argc != 2) {
		fprintf(stderr,"usage: %s [0-61]\n",argv[0]);
		exit(1);
	}
	sscanf(argv[1],"%lu",&request);
	setBrightness(request);
	return(0);
}
SHAR_EOF
fi # end of overwriting check
if test -f 'makefile'
then
	echo shar: will not over-write existing file "'makefile'"
else
cat << \SHAR_EOF > 'makefile'
dim: dim.o
	cc dim.o -o dim

dim.shar: dimlogin dim.c makefile
	shar dimlogin dim.c makefile > dimlogin.shar

all: dim dim.shar
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0