Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
scripting help

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Squashman's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
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 - User Desktop Experience
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 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
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 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
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 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
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 - User Desktop Experience
-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 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
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 - User Desktop Experience
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 05:13 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.