Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a script here that I want to create as a port in freebsd and then make it as package so that I can install on some machines. script is below.

if [ ! -f "/suid.old" ]
find / -perm -4000 -o -perm -2000 -ls > /suid.old
find / -perm -4000 -o -perm -2000 -ls > /
diff suid.old > newchanges
exit 0
if [ -s "/newchanges" ]
  mail -s "changes has occured"
  mail -s "No changes has occured" /newchanges

How can I accomplish this?

share|improve this question

2 Answers 2

If you're only installing that one small script, I'd just do it manually. You could use a shar file, but that seems like overkill.

The biggest issues I see are first, that bash is going to be located in different locations on different systems, but there's nothing in your script that's Bash-specific, so you could change your shebang to:



#!/usr/bin/env bash

for portability.

Second, you will need to choose a location for your script. It strikes me that /usr/local/bin would be as good as any.

Third, you will need to chown to set the ownership and chmod to set the permissions.

Fourth, you should choose better locations for your output files. If they are only for temporary use, then they should be created in /tmp rather than the root directory where you have suid.old and going, or the current directory where you have newchanges going. Otherwise, somewhere in var might be where you'd want to put more persistent data. Perhaps /var/local/suid.

Fifth, the exit prevents the second if from ever being evaluated so no mail will ever be sent.

Sixth, you might want to mv suid.old at some point so the next time you do your check it's comparing the most recent saved data.

Seventh, your last mail command should have the file piped or redirected in. It won't work as an argument. And the two mail commands should be swapped so you're not mailing a file when it's empty and are mailing it when it's not.

if [ -s "/newchanges" ]
  mail -s "No changes have occurred" < /path/to/newchanges
  mail -s "changes have occurred"
share|improve this answer

A port for one shell script is beyond overkill -- As Dennis said this is something I would copy to individual machines as needed (or create a package manually, but this is a pain).

I'm also not sure this has sufficient general utility to make it into the official ports collection (in particular, there is already a "setuid binaries" check as part of the daily security audit).

All that said, details on creating a port can be found in the Porter's Handbook, and you can always roll a local port just for your site.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.