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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for Reload services

Status
Not open for further replies.

biondo68

Technical User
Jul 4, 2003
103
IT
Hi,

I have a script for reload services, in this case Tomcat .

I want that only root can run the batch

Can you suggest an efficient way ?

my script


#!/bin/bash


if [ $(date "+%k") -lt 8 -o $(date +"%k") -gt 17 -o $(date +"%a") == "Sat" -o $(date +"%a") == "Sun" ]

then
echo "Cannot run between 09:00 and 18:00"
echo "Non e' possibile eseguire il Reload di Tomcat prima delle ore 09:00 e dopo le ore 18:00"
else
echo "Run Program Tomcat"
echo "Reload di Tomcat"


case $1 in
stop)
echo "/command/sv down /service/tomcat_a"
;;
start)
echo "/command/sv up /service/tomcat_a"
;;
restart)
echo "/command/sv down /service/tomcat_a"
#sleep 20
#rm -rf /opt/tomcat/work/Catalina/*
#sleep 20
echo "/command/sv up /service/tomcat_a"
;;
kill)
echo "/command/sv down /service/tomcat_a"
echo "/command/sv kill /service/tomcat_a"
;;
*)
echo "Usage: $0{stop|start|restart|kill}"
;;
esac

fi

Thanks
 
Hi,

Maybe I have not explained well .

I want that ROOT can run the script and the other users can not perform the script on Saturday and Sunday and the hours
present in the scripts .
 

correct or you can use another way ?

if [ $(date "+%k") -lt 8 -o $(date +"%k") -gt 17 -o $(date +"%a") == "Sat" -o $(date +"%a") == "Sun" ] && [ $USER != "root" ]

then
echo "Cannot run between 09:00 and 18:00"
else
echo "Run Program Tomcat"

case $1 in
stop)
echo "/command/sv down /service/tomcat_a"
;;
start)
echo "/command/sv up /service/tomcat_a"
;;
restart)
echo "/command/sv down /service/tomcat_a"
#sleep 20
#rm -rf /opt/tomcat/work/Catalina/*
#sleep 20
echo "/command/sv up /service/tomcat_a"
;;
kill)
echo "/command/sv down /service/tomcat_a"
echo "/command/sv kill /service/tomcat_a"
;;
*)
echo "Usage: $0{stop|start|restart|kill}"
;;
esac

fi


Thanks
 
Actually, testing "[tt]$ROOT[/tt]" is not safe since anyone can type "[tt]ROOT=root[/tt]" before running it and it will run. Better to use something like...

Code:
... && [ "`whoami`" != "root" ]

Or "[tt]who am i[/tt]" depending on your system.


 
Hi

Just a note I read somewhere : the superuser should not be checked by user name "root", but by user id 0. Though not a usual practice, the user name may be changed, but the id not.

That would mean to change [tt]"`whoami`" != "root"[/tt] with [tt]"`id -u`" != "0"[/tt].


Feherke.
feherke.ga
 
Hi

I used the solution with " id " .

Thanks for yours suggestions.

Biondo68
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top