There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
UNIX/Linux
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > UNIX/Linux >
scripting help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Squashman's Avatar
Distinguished Member with 12,604 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
06-Mar-2004, 08:45 PM #1
scripting help
I work for a school district and it is the schools policy not to allow students to have executable files in their home directories. So I have been using ncpmount (netware server) on my linux box and executing the following commands

find /Path/to/students -type f | xargs file | grep executable

This works fine if there are no directories or filenames with spaces in them. If it finds a filename with a space in it, the command will freeze and I will have to break out of it. Not sure how I can preserve the spaces from what the find command outputs. I have tried putting quotes around everything under the sun but have had no luck with this.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - Windows Shell/User
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
08-Mar-2004, 04:39 AM #2
How about something like:

find path-to-student-directories -type f -perm +111

I think that will locate all executable files (owner, group or world) regardless of the name.

Hope this helps.
Squashman's Avatar
Distinguished Member with 12,604 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
08-Mar-2004, 07:15 PM #3
Not so sure that would work on a Netware mounted volume but I will give it a try. Netware doesn't not have an execute in its file attributes.
Squashman's Avatar
Distinguished Member with 12,604 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
09-Mar-2004, 02:57 PM #4
I got it figured out. Here is the code if anyone wants to try it out.

Code:
# Filename: file.sh
# Date: March 9, 2004
# Purpose: Used to find executable files

clear

echo "Enter path name:"
read THEPATH
NAMEPART1=`echo $THEPATH | tr -d "/"`
NAMEPART2=`date +-run-%Y-%m-%d`
FILENAME=Exe_Violators_$NAMEPART1$NAMEPART2

echo "Now running the file command and grep  for "$THEPATH
# Time Stamping when the script started
date > $FILENAME

find $THEPATH -type f | sed -e 's/ /\\ /g' | xargs file | grep executable >> $FILENAME

# Time Stamping when the script ended
date >> $FILENAME
Now my only problem is if they have executables inside zip files. The file -z option does not seem to work to well.
Squashman's Avatar
Distinguished Member with 12,604 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
14-Mar-2004, 10:48 AM #5
Well I changed my script again. I needed to account for all special characters in the filenames. So the only thing I could think of was to use sed to put quotes around the filenames. But if a user puts a " in their filename the script will crap out because Xargs finds an unmatched quote. Anyone got any ideas.

Code:
# Filename: file.sh
# Date: March 9, 2004
# Purpose: Used to find executable files

clear

echo "Enter path name:"
read THEPATH
NAMEPART1=`echo $THEPATH | tr -d "/"`
NAMEPART2=`date +-run-%Y-%m-%d`
FILENAME=Exe_Violators_$NAMEPART1$NAMEPART2

echo "Now running the file command and grep  for "$THEPATH
# Time Stamping when the script started
date > $FILENAME

find $THEPATH -type f | sed -e 's/^/\"/' -e 's/$/\"/' | xargs file -z | grep executable >> $FILENAME

# Time Stamping when the script ended
date >> $FILENAME
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - Windows Shell/User
-Sx-'s Avatar
Junior Member with 24 posts.
 
Join Date: Mar 2004
Location: Planet Earth
29-Mar-2004, 11:27 PM #6
Did you post this on Little Black Dog as well? 2FF =)
-Sx-'s Avatar
Junior Member with 24 posts.
 
Join Date: Mar 2004
Location: Planet Earth
29-Mar-2004, 11:48 PM #7
Anyways, why not just -

find /path/to/students -type f -exec chmod a-x {} \;

Or, better, mount their filesystem -o noexec

(Why play with them?)


-Sx-
Squashman's Avatar
Distinguished Member with 12,604 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
30-Mar-2004, 09:47 AM #8
Quote:
Originally posted by -Sx-:
Anyways, why not just -

find /path/to/students -type f -exec chmod a-x {} \;

Or, better, mount their filesystem -o noexec

(Why play with them?)


-Sx-
Read my first post. I am Mounting a netware volume to my Linux box using ncpmount to run this script.

My problem has basically been solved with this script. You cannot name a filename in Windows with a quote in it so I do not have to worry about unmatched quote errors.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - Windows Shell/User
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 04:50 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.