Uploaded UNIX Scripts

click here to return to the dr-jan.com home page

This page contains UNIX scripts and articles uploaded by fellow browsers. Please feel free to contribute a script or an article to unix_scripts at dr-jan.com (you'll need to translate that address, unfortunately I have to do this to avoid spam). Use your browser's find-on-this-page facility to search for specific scripts.


The URL for SCO UNIX documentation has changed, now that most of SCO belongs to Caldera:

http://www.caldera.com/support/docs/

Jan Ives <scripts@dr-jan.com>
- Monday, June 17, 2002 at 13:21:52 (GMT)
Victor recently asked how he could delete all files in a
directory which were older than a specified date/time.

We developed the script shown below, which is written for
the Korn shell (ksh).

The script works out the date 2 days ago, then uses 'touch'
to create a file with that date/time stamp. The test
command is then used to compare the date on the new file
with the date on the files being processed. Note that the
script uses the shorthand '[' notation for the test command.

Be aware that the double parenthesis notation '$((today-2))'
is Korn-shell specific. If you're using a different shell
you'll probably have to use the 'expr' command instead.

Thanks to Victor for permission to post his script here.

-----8<-----
#!/usr/local/bin/ksh

# Find the numeral for today

today=`date +%d`
newmonth=`date +%m`

# Go back to cutoff date

cutoffdate=$(($today-2))

# Adjust for negative days

if [ $cutoffdate -le 0 ] ; then
newmonth=$(($newmonth-1))
case $newmonth in

1|3|5|7|8|10|12)
cutoffdate=$((31+$cutoffdate)) ;;

4|6|9|11)
cutoffdate=$((30+$cutoffdate)) ;;

2) cutoffdate=$((28+$cutoffdate)) ;;
esac

# If the month is under 10, then add a zero to keep format correct.

if [ $newmonth -le 9 ] ; then
newmonth=0$newmonth

fi
fi

# If the month is under 10, then add a zero to keep format correct.


# If it's less then 10 days, add a 0. If it is in the previous month
# adjust the month to the previous month.

if [ $cutoffdate -le 9 ] ; then
cutoffdate=0$cutoffdate
fi

# Create holder for new cutoff date

cutoff=`date +$newmonth$cutoffdate%H%M`
echo $cutoff

# Create file to be compared against for the creation date

/usr/bin/touch -am -t $cutoff /root/scripts/now

# Remove files older than the file created above.

for i in /ftp/pub/*
do
if [ $i -ot /root/scripts/now ] ;
then
/usr/bin/rm $i
fi
done

Revd Dr Jan Ives <scripts@dr-jan.com>
- Friday, August 17, 2001 at 08:07:49 (PDT)
Finding files with the find command.

The most common use of the find command is something like:

find / -name foo


This will search for the file named `foo' in the root
directory and every subdirectory below it.

The first parameter specifies which directory to start
searching in.

The -name tells find to look for a specific name. You can
use wildcards in the name, but if you do, enclose the
whole thing in single quotes. For example,

find / -name '*foo*'


will find any file with `foo' anywhere in their name,
anywhere on the machine.

Once a file has been found, there are lots of things
you can do to it (do a
man find
and check
out
-exec
), but by default the pathname of
the file is printed on your terminal screen.

Check the man pages for find - there are lots of useful
options available.

Revd Dr Jan Ives <scripts@dr-jan.com>
- Friday, November 10, 2000 at 06:43:19 (PST)

Mounting CD-ROMs

If you're using Redhat Linux and you have an ATAPI (IDE)
CD-ROM drive you'll need to know which bus it's attached
to (primary or secondary) and whether it's the master or
slave drive on that bus. Using the table below to trans-
late, you can build up the correct mount command.

primary master /dev/hda
primary slave /dev/hdb
secondary master /dev/hdc
secondary slave /dev/hdd

The second part of the mount command specifies an exist-
ing directory. The contents of the CD will be visible in
this directory.

In the example below the CD-ROM drive is connected up as
the primary slave drive and my mount point is /mnt/cdrom

mount /dev/hdb /mnt/cdrom


Revd Dr Jan Ives <scripts@dr-jan.com>
- Thursday, November 02, 2000 at 07:45:44 (PST)
Talking directly to sendmail.

You can use telnet to talk directly to sendmail. This allows you to create mail from a different account.

$ telnet your.mailserver.address.com 25

You should get an introductory message from sendmail.

> helo your.domain.com

Sendmail responds with address details and 'pleased to meet you'

> mail from: person@address.mail.is.from.com

Sendmail should echo back the sender address and 'sender OK'

> rcpt to: person@address.to.send.message.to.com

Sendmail should again echo the address and 'recipient OK'

> data

Sendmail responds with something like 'Enter mail, end with "." on a line by itself'

> subject: enter your subject line here
> and then type in the body of
> your message. End the message
> with . as instructed.
> .

Sendmail responds with 'message accepted for delivery' (hopefully :-)

Quit your telnet session by typing Ctrl-], then 'quit' at the telnet prompt.

Note, this procedure will also work with MS Exchange Server, although some of the responses are different.

Revd Dr Jan Ives <scripts@dr-jan.com>
- Monday, June 05, 2000 at 02:20:16 (PDT)
Here's a handy script to help you in the program/run/debug cycle.

#!/bin/sh
file="$1"
if [ -z "$file" ]; then
exit;
fi
while [ 1 ]; do
vi $file
chmod 755 $file
$file
echo -n "Hit [return], or [Ctrl-C] to stop"; read x
done

line 1: Define the shell
line 2: Read in the filename paswwd.
line 3: Chech weather there is a filename entered
line 4: Exit if there is no filename entered
line 6 : Begin an endless loop
line 7: Loades the file to be worked on.
line 8: Makes the file executable
line 9 : executes the file
line 10: Continues or stops the process

Robert Lee Binkley Jr.


Lee Binkley <lee.binkley@mail.state.ar.us>
- Monday, January 24, 2000 at 09:36:37 (PST)
crontab files

This is what the numbers at the front of a crontab file mean

minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-6 (Sunday is zero)

Use a star (*) to indicate all possible values.

Do a man crontab for more details :-)

dr jan <jan@dr-jan.com>
- Tuesday, May 25, 1999 at 04:27:10 (PDT)
Here are a few interesting tips I picked up on a
SCO UnixWare 7 Admin I course recently.

Multiscreens
============
OpenServer5 used alt-F[1-12] to switch between screens.
Recent versions with a GUI use ctrl-alt-F[1-12]. UnixWare
uses ctrl-alt-F[1-8]. Note UW is restricted to 8 screens.

Interrupt
=========
UnixWare7 defaults to using ctrl-c as the interrupt,
rather than delete.

SCOAdmin
========
If you have dtterm running in the GUI and you want to run
the character (CHARM) version of scoadmin rather than the
graphical version set the CHARM environment variable first:
CHARM=true; export CHARM
scoadmin will then invoke the character based version.

Revd Dr Jan Ives <doc@dr-jan.com>
- Tuesday, April 13, 1999 at 01:46:06 (PDT)

It would appear that all the SCO reference manuals are available
online. This is the URL for vi:

http://www.sco.com/cgi-bin/ssl_getmanpage?vi+C+OS5

The URL is constructed from the name of the command, the
section of the manual that command is in and the operating
system version. As far as I can see.

Revd Dr Jan Ives <doc@dr-jan.com>
- Wednesday, January 27, 1999 at 14:53:59 (PST)


Dr jan's tip from the top for today is...

Under no circumstances should you attempt to boot SCO
OpenServer 5.0.5 directly from the CDROM, even if your CD
supports this.

I tried a couple of times and after I'd answered all the questions and
the filesystems had been made on the hard disk I got:

Reading from Install Source: 10KB/ramFS/extractProd/extractAll
terminated by signal 8.

Press Enter to continue.

When I pressed Enter, I got the 'safe to power off / any key to
reboot' screen.

I retried the same installation again, but booting from the SCO boot
floppy, and all seems to be going OK. Oh all right, it's got a bit
further that it did before. That's all I'm saying :-)

Revd Dr Jan Ives <doc@dr-jan.com>
- Wednesday, January 27, 1999 at 14:32:22 (PST)


I was asked today for a script to kill all the processes
for a specified user.

The basic approach is to use ps -u username to find the
process numbers for the user, then use cut to chop out
just the process IDs. Then sort them into reverse order
so that higher numbered (and therefore more recent)
processes are killed first. Finally issue the kill command
within a for loop.

If there are any processes left for that user then repeat
the above with a kill -9 command.

Details to follow in a later article.

Copyright 27-jan-1999 Revd Dr Jan Ives. All rights reserved.

Revd Dr Jan Ives <doc@dr-jan.com>
- Wednesday, January 27, 1999 at 14:19:27 (PST)



Copyright 1999-2003 Revd Dr Jan Ives. All rights reserved. Version 1.03, last manually updated on 14-Aug-2003.