Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

help me with this this problem. so far i have "find / -perm -4000 -o -perm -2000 | xargs ls -l > suild.list" argument that i want to write as a bash script.

I would like to write this as a bash script and be be able to run this nightly everyday. But im not familiar with the unix scripting language.

for crontab job, i need to write as * 24 * * *? I think? but i'm having trouble writing as a script.

share|improve this question
    
24 might work, but I would put a zero there. –  Dennis Williamson Feb 5 '10 at 3:03

4 Answers 4

It's not necessary to use xargs in this case. Just use -ls with find.

#!/bin/bash
find / -perm -4000 -o -perm -2000 -ls > suild.list

If you want to mail it and log it by appending to the file:

#!/bin/bash
find / -perm -4000 -o -perm -2000 -ls | tee -a suild.list
share|improve this answer

Your command is already a bash script.

You would need to add a header:

#!/usr/bin/env bash

And you would need to set the executable (+x) bit on the script.

If you wanted to mail the results out to the administrator, you could remove the redirect to suild.list at the end.

share|improve this answer

!/bin/bash

find / -perm -4000 -o -perm -2000 -ls | tee -a suild.list

How can i use an if / else statement with this if wanted to create the full script. e.g. i wanted to say if this suild.list file does not exist, then use the find command to generate the new suid or else use the find / -perm -4000 -o -perm -2000 -ls | tee -a suild.list argument and compare the changes if any new suid has been created. for security reasons.

share|improve this answer

It sounds like you don't so much as want a full list each time the script is run but rather a list of any new/uknown files that are set suid/guid. If that's so then:

Get a list of current results:

# find / -path '/proc' -prune -perm -4000 -o -perm -2000
/usr/bin/write
/usr/bin/wall
/usr/bin/crontab
/usr/bin/locate
/usr/bin/ssh-agent

Create a shell script that find and compares the results to the previous list. The list is just a variable in the script. You could have it be it's own file though.

#!/bin/bash

approved="
/usr/bin/write
/usr/bin/wall
/usr/bin/crontab
/usr/bin/locate
/usr/bin/ssh-agent
"

results=$(/usr/bin/find / -path '/proc' -prune -perm -4000 -o -perm -2000)

for line in $results; do
    if ! echo -n $approved | /bin/grep -q $line; then
        ls -a $line
    fi
done

Result when new file shows up:

# ./suid_check.sh 
/sbin/netreport

Throw it in cron and configure cron to email STDOUT.

share|improve this answer

Your Answer

 
discard

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