INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Script for Reload services

Script for Reload services

(OP)
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

RE: Script for Reload services

(OP)
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 .

RE: Script for Reload services

(OP)

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

RE: Script for Reload services

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

CODE

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

Or "who am i" depending on your system.


RE: Script for Reload services

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 "`whoami`" != "root" with "`id -u`" != "0".

Feherke.
feherke.ga

RE: Script for Reload services

(OP)
Hi

I used the solution with " id " .

Thanks for yours suggestions.

Biondo68

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close