Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script with super user

Status
Not open for further replies.

dl01

Technical User
Jun 25, 2001
15
NL
I want to add a script to my crontab to delete some logs that grow
very quickly on a weekly basis. Unfortunatlty when the files are
created only root has the delete privledges. How can I run a script
from a regular users login that will change to super user, delete the
files then change back?
 
I think you would do this by using setuid, but I wouldn't recommend this (security risk). It's more likely you would want to create a script that cron will run as root on a regular basis. This would run whether you logged into the system or not.

script:

#!/bin/sh
cd /var/logs
#please check the man page on find for exact syntax
find . -atime +45 -exec rm -r {} \;

how to enter into cron

# su
password:
(in csh or tcsh)
# setenv EDITOR vi (or your favorite editor)
# crontab -e

(the cron file will open in an editor, add the appropriate entry, such as run once a week, sunday at 11:30 am)

30 11 * * 0 /scripts/scriptname.sh


-jared
 
Take a look at sudo


It allows you to run one or more commands as any other user, and is a lot more secure than using setuid.

It's very easy to install & set-up

or could you not just add the remove stuff to root's crontab? --
| Mike Nixon
| Unix Admin
| ----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top