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 acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
scripting help

Reply  
Thread Tools
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
06-Mar-2004, 09: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.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
08-Mar-2004, 05: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
08-Mar-2004, 08: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
09-Mar-2004, 03: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
14-Mar-2004, 11: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
-Sx-'s Avatar
Junior Member with 24 posts.
 
Join Date: Mar 2004
Location: Planet Earth
30-Mar-2004, 12:27 AM #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
30-Mar-2004, 12:48 AM #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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
30-Mar-2004, 10: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.
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
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:19 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.